From f0cd283033251a3b2fb4405218579c1aa52f0490 Mon Sep 17 00:00:00 2001 From: balika011 Date: Sun, 29 Jul 2018 22:11:11 +0200 Subject: [PATCH] Fix header and gcc params --- tools/linux/libGameLogic.h | 309 +++++++++++++++++----------- tools/linux/part5_walking_speed.cpp | 20 +- tools/linux/part7_teleport.cpp | 53 +++-- tools/linux/part8_eggs.cpp | 59 +++--- 4 files changed, 240 insertions(+), 201 deletions(-) diff --git a/tools/linux/libGameLogic.h b/tools/linux/libGameLogic.h index f77e010..391f4e3 100644 --- a/tools/linux/libGameLogic.h +++ b/tools/linux/libGameLogic.h @@ -1,3 +1,14 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + class IAchievement; class IQuestState; class IQuest; @@ -203,34 +214,6 @@ template struct ActorRef { bool operator<(const ActorRef &) const; }; -//WriteStream -/* -template< typename IActor> -struct ActorRef { - IActor *m_object; -}; - -template< typename IPlayer> -struct ActorRef { - IPlayer *m_object; -}; - -template< typename NPC> -struct ActorRef { - NPC *m_object; -}; - -template< typename Bear> -struct ActorRef { - Bear *m_object; -}; - -template< typename BearChest> -struct ActorRef { - BearChest *m_object; -};*/ - - class IActor { public: virtual ~IActor(); @@ -328,9 +311,8 @@ class Actor : public IActor { bool MoveToRandomLocationInRadius(float); bool MoveToActor(IActor *); bool GetState(const std::string &); - //virtual void UpdateState(const std::string &, bool); - //virtual void TriggerEvent(std::__cxx11::basic_string, std::allocator > const&, IActor*, bool); - //virtual void TriggerEvent(const std::string &, IActor *, bool); + virtual void UpdateState(const std::string &, bool); + virtual void TriggerEvent(const std::string &, IActor *, bool); const std::map & GetStates(); IActor * LineTraceTo(const Vector3 &); void FireBullets(IItem *, int32_t, DamageType, float, uint32_t, float); @@ -760,7 +742,7 @@ class Player : public Actor, public IPlayer { virtual IInventory * GetInventory(); virtual uint32_t GetItemCount(IItem *); virtual uint32_t GetLoadedAmmo(IItem *); - virtual bool AddItem(IItem *, uint32_t, bool); + virtual bool AddItem(IItem *item, uint32_t count, bool allowPartial); virtual bool RemoveItem(IItem *, uint32_t); bool PerformAddItem(IItem *, uint32_t, bool); bool PerformRemoveItem(IItem *, uint32_t); @@ -1247,96 +1229,21 @@ class FastTravelDestination { void AddToListIfValid(std::vector &, Player *, const std::string &); }; -class MasterServerConnection; -class GameServerConnection; -class CharacterInfo; +struct SSL_CTX; +class SSLSocket; -class GameAPI { +class ThreadActionQueue { private: - void InitObjects(); - void StartServerListener(const ServerInfo &); + std::mutex m_mutex; + std::vector, std::allocator > > m_actions; + + std::vector, std::allocator > > GetActionsForThisTick(); public: - GameAPI(); - void InitLocal(ILocalPlayer *); - void InitClient(ILocalPlayer *); - void InitServer(const char *, uint16_t, int32_t, const char *, uint16_t, const char *, const char *, const char *); - void Shutdown(); - void Tick(float); - bool IsAuthority(); - bool IsDedicatedServer(); - bool IsTransitioningToNewServer(); - IItem * GetItemByName(const char *); - IQuest * GetQuestByName(const char *); - FastTravelDestination * GetFastTravelDestination(const std::string &); - IAchievement * GetAchievement(const char *); - IAchievementList * GetAchievements(); - std::vector > GetAchievementList(); - std::vector > GetGoldenEggList(); - size_t GetGoldenEggCount(); - virtual bool SpawnActor(IActor *, const Vector3 &, const Rotation &, bool); - virtual bool SpawnActorAtNamedLocation(IActor *, const char *); - virtual bool SpawnRemotePlayer(IPlayer *, const Vector3 &, const Rotation &); - virtual void DamageInRadius(IActor *, IItem *, const Vector3 &, float, int32_t, DamageType); - virtual size_t GetNamedLocationPoints(const char *, LocationAndRotation *&); - virtual void FreeNamedLocationPoints(LocationAndRotation *); - std::vector GetNamedLocationPointList(const char *); - bool GetNamedLocationPoint(const std::string &, LocationAndRotation &); - std::vector GetSpawnPoints(const char *); - void GiveAll(IPlayer *); - virtual Vector3 GetDirectionFromRotation(const Rotation &); - virtual Rotation GetRotationFromDirection(const Vector3 &); - virtual void OnWeaponFired(IItem *, const Vector3 &, const Vector3 &); - virtual void OnBulletHitActor(IItem *, IActor *, const Vector3 &, const Vector3 &); - virtual void OnBulletHitWorld(IItem *, const Vector3 &, const Vector3 &); - virtual void OnLog(const char *); - void Log(const char *); - virtual void OnMasterServerConnected(bool, const char *, const char *); - virtual void OnLoginComplete(bool, const char *, bool, CharacterInfo *, size_t); - virtual void OnRegisterComplete(bool, const char *, const char *, bool); - virtual void OnCreateCharacterComplete(bool, const char *, int32_t); - virtual void OnDeleteCharacterComplete(bool, int32_t); - virtual void OnJoinGameServerComplete(bool, const char *, bool, const char *, uint16_t, const char *); - virtual void OnGameServerConnected(bool, const char *, const Vector3 &, const Rotation &); - virtual void OnTransitionToNewServer(); - virtual void OnSubmitAnswerComplete(bool, const char *); - virtual void OnTeammatesListed(const char **, const char **, size_t); - virtual uint32_t GetDefaultCircuitInputs(const char *); - virtual size_t GetCircuitOutputCount(const char *); - virtual void GetCircuitOutputs(const char *, uint32_t, bool *, size_t, bool *); - LootTier * GetLootTier(uint32_t); void Enqueue(const std::function &); - void Process(const std::function &); - MasterServerConnection * GetMasterServer(); - void UpdatePlayerCounts(); - void GetTeammates(); - void Login(const char *, const char *); - void CreateCharacter(const char *, uint8_t, uint32_t *); - void DeleteCharacter(int32_t); - void JoinGameServer(int32_t, bool); - void SubmitAnswer(const char *, const char *); - GameServerConnection * GetGameServer(); - void ConnectToGameServer(const char *, uint16_t, int32_t, const char *); - bool IsConnectedToMasterServer(); - bool IsConnectedToGameServer(); - int32_t GetUserId(); - int32_t GetCharacterId(); - const char * GetUserName(); - const char * GetTeamName(); - const char * GetTeamHash(); - void ConnectToMasterServer(const char *, uint16_t, const char *); - void DisconnectFromMasterServer(); - void Register(const char *, const char *, const char *); - void TransitionToNewGameServer(); - Actor * CreateRemoteActorByName(const std::string &, bool); - Actor * CreateRemoteActorByNameWithOwner(const std::string &, bool, IActor *); - bool HasActorFactory(const std::string &); - int32_t GetTeamPlayerCount(); - int32_t GetTotalPlayerCount(); + void Process(); + void Clear(); }; - -/* - class ServerConnection { protected: bool m_running; @@ -1360,9 +1267,76 @@ class ServerConnection { bool IsReadyToDisconnect() const; void ProcessGameThreadActions(); void Disconnect(); -} +}; + +class MasterServerConnection : public ServerConnection { + protected: + SSL_CTX *m_context; + SSLSocket *m_sock; + void NotifyDisconnect(); + virtual const char * GetServerType(); + public: + struct TeamMemberInfo { + std::string name; + std::string location; + }; + + struct CharacterInfo { + int32_t id; + std::string name; + std::string team; + std::string location; + uint8_t avatar; + uint32_t colors[4]; + uint32_t flags; + bool transitioning; + Vector3 transitionPoint; + int32_t transitionHealth; + int32_t transitionMana; + bool transitionPvP; + bool admin; + std::map, QuestStateInfo, std::less >, std::allocator const, QuestStateInfo> > > quests; + std::string activeQuest; + std::map, ItemCountInfo, std::less >, std::allocator const, ItemCountInfo> > > items; + std::vector, std::allocator > > equipped; + uint8_t activeSlot; + std::set, std::less >, std::allocator > > pickups; + }; + + MasterServerConnection(); + virtual ~MasterServerConnection(); + void Connect(const std::string &, uint16_t, const std::string &, + const std::function &, const std::basic_string &)> &); + void Login(const std::string &, const std::string &, + const std::function &, int, const std::basic_string &, const std::basic_string &, bool)> &); + void Register(const std::string &, const std::string &, const std::string &, + const std::function &, int, const std::basic_string &, const std::basic_string &, bool)> &); + void GetPlayerCounts(const std::function &); + void GetTeammates(const std::function > &)> &); + void GetCharacterList(const std::function > &)> &); + void CreateCharacter(const std::string &, uint8_t, uint32_t *, + const std::function &, int)> &); + void DeleteCharacter(int32_t, const std::function &); + void JoinGameServer(int32_t, + const std::function &, bool, const std::basic_string &, unsigned short, const std::basic_string &, const MasterServerConnection::CharacterInfo &)> &); + void GetFlag(const std::string &, const std::function &, bool)> &); + void SubmitFlag(const std::string &, const std::function &)> &); + void SubmitAnswer(const std::string &, const std::string &, + const std::function &)> &); + void Heartbeat(); + bool ValidateCharacterToken(int32_t, const std::string &, MasterServerConnection::CharacterInfo &); + void AddServerToPool(const std::string &, uint16_t); + bool CharacterRegionChange(int32_t, const std::string &, const Vector3 &, int32_t, int32_t, bool); + void StartQuest(Player *, const std::string &, const std::string &, uint32_t); + void UpdateQuest(Player *, const std::string &, const std::string &, uint32_t); + void CompleteQuest(Player *, const std::string &); + void SetActiveQuest(Player *, const std::string &); + void UpdateItems(Player *); + void MarkAsPickedUp(Player *, const std::string &); +}; +class TCPSocket; class GameServerConnection : public ServerConnection { protected: @@ -1437,8 +1411,90 @@ class GameServerConnection : public ServerConnection { void SetPvPDesired(bool); void SubmitDLCKey(const std::string &); void SetCircuitInputs(const std::string &, uint32_t); -} -*/ +}; + +class GameAPI { + private: + void InitObjects(); + void StartServerListener(const ServerInfo &); + public: + GameAPI(); + void InitLocal(ILocalPlayer *); + void InitClient(ILocalPlayer *); + void InitServer(const char *, uint16_t, int32_t, const char *, uint16_t, const char *, const char *, const char *); + void Shutdown(); + void Tick(float); + bool IsAuthority(); + bool IsDedicatedServer(); + bool IsTransitioningToNewServer(); + IItem * GetItemByName(const char *); + IQuest * GetQuestByName(const char *); + FastTravelDestination * GetFastTravelDestination(const std::string &); + IAchievement * GetAchievement(const char *); + IAchievementList * GetAchievements(); + std::vector > GetAchievementList(); + std::vector > GetGoldenEggList(); + size_t GetGoldenEggCount(); + virtual bool SpawnActor(IActor *, const Vector3 &, const Rotation &, bool); + virtual bool SpawnActorAtNamedLocation(IActor *, const char *); + virtual bool SpawnRemotePlayer(IPlayer *, const Vector3 &, const Rotation &); + virtual void DamageInRadius(IActor *, IItem *, const Vector3 &, float, int32_t, DamageType); + virtual size_t GetNamedLocationPoints(const char *, LocationAndRotation *&); + virtual void FreeNamedLocationPoints(LocationAndRotation *); + std::vector GetNamedLocationPointList(const char *); + bool GetNamedLocationPoint(const std::string &, LocationAndRotation &); + std::vector GetSpawnPoints(const char *); + void GiveAll(IPlayer *); + virtual Vector3 GetDirectionFromRotation(const Rotation &); + virtual Rotation GetRotationFromDirection(const Vector3 &); + virtual void OnWeaponFired(IItem *, const Vector3 &, const Vector3 &); + virtual void OnBulletHitActor(IItem *, IActor *, const Vector3 &, const Vector3 &); + virtual void OnBulletHitWorld(IItem *, const Vector3 &, const Vector3 &); + virtual void OnLog(const char *); + void Log(const char *); + virtual void OnMasterServerConnected(bool, const char *, const char *); + virtual void OnLoginComplete(bool, const char *, bool, MasterServerConnection::CharacterInfo *, size_t); + virtual void OnRegisterComplete(bool, const char *, const char *, bool); + virtual void OnCreateCharacterComplete(bool, const char *, int32_t); + virtual void OnDeleteCharacterComplete(bool, int32_t); + virtual void OnJoinGameServerComplete(bool, const char *, bool, const char *, uint16_t, const char *); + virtual void OnGameServerConnected(bool, const char *, const Vector3 &, const Rotation &); + virtual void OnTransitionToNewServer(); + virtual void OnSubmitAnswerComplete(bool, const char *); + virtual void OnTeammatesListed(const char **, const char **, size_t); + virtual uint32_t GetDefaultCircuitInputs(const char *); + virtual size_t GetCircuitOutputCount(const char *); + virtual void GetCircuitOutputs(const char *, uint32_t, bool *, size_t, bool *); + LootTier * GetLootTier(uint32_t); + void Enqueue(const std::function &); + void Process(const std::function &); + MasterServerConnection * GetMasterServer(); + void UpdatePlayerCounts(); + void GetTeammates(); + void Login(const char *, const char *); + void CreateCharacter(const char *, uint8_t, uint32_t *); + void DeleteCharacter(int32_t); + void JoinGameServer(int32_t, bool); + void SubmitAnswer(const char *, const char *); + GameServerConnection * GetGameServer(); + void ConnectToGameServer(const char *, uint16_t, int32_t, const char *); + bool IsConnectedToMasterServer(); + bool IsConnectedToGameServer(); + int32_t GetUserId(); + int32_t GetCharacterId(); + const char * GetUserName(); + const char * GetTeamName(); + const char * GetTeamHash(); + void ConnectToMasterServer(const char *, uint16_t, const char *); + void DisconnectFromMasterServer(); + void Register(const char *, const char *, const char *); + void TransitionToNewGameServer(); + Actor * CreateRemoteActorByName(const std::string &, bool); + Actor * CreateRemoteActorByNameWithOwner(const std::string &, bool, IActor *); + bool HasActorFactory(const std::string &); + int32_t GetTeamPlayerCount(); + int32_t GetTotalPlayerCount(); +}; class KeyVerifier { public: @@ -1447,14 +1503,15 @@ class KeyVerifier { enum EnemyRank {NormalEnemy, EliteEnemy, LegendaryEnemy}; -class LootTable; - - class LootTable { private: + struct TableEntry { + uint32_t value; + float weight; + }; float m_dropChance; - //std::vector m_tiers; - //std::vector m_counts; + std::vector > m_tiers; + std::vector > m_counts; float m_totalTierWeight; float m_totalCountWeight; std::vector m_additionalItems; @@ -1574,3 +1631,7 @@ class Magmarok : public Enemy { virtual void Tick(float); virtual void OnPrepareAttack(Actor *); }; + +extern GameAPI *Game; +extern World *GameWorld; + diff --git a/tools/linux/part5_walking_speed.cpp b/tools/linux/part5_walking_speed.cpp index 852068e..7b330d5 100644 --- a/tools/linux/part5_walking_speed.cpp +++ b/tools/linux/part5_walking_speed.cpp @@ -1,23 +1,15 @@ -#include -#include -#include -#include -#include -#include #include "libGameLogic.h" // cd clients/linux_updated/PwnAdventure3_Data/PwnAdventure3/PwnAdventure3/Binaries/Linux -// g++ part5_walking_speed.cpp -shared -fPIC -std=c++11 -o part5_walking_speed.so +// g++ part5_walking_speed.cpp -shared -fPIC -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0 -o part5_walking_speed.so // LD_PRELOAD=part5_walking_speed.so ./PwnAdventure3-Linux-Shipping void World::Tick(float f) { // see libGameLogic.h for the class/object definitions - ClientWorld* world = *((ClientWorld**)(dlsym(RTLD_NEXT, "GameWorld"))); - IPlayer* iplayer = world->m_activePlayer.m_object; - Player* player = ((Player*)(iplayer)); - Actor* actor = ((Actor*)(iplayer)); - player->m_walkingSpeed = 99999; - //printf("[LO] IPlayer.GetPlayerName: %s\n", iplayer->GetPlayerName()); - //printf("[LO] player->m_mana: %d\n", player->m_mana); + ClientWorld *world = (ClientWorld *) GameWorld; + IPlayer* iplayer = world->m_activePlayer.Get(); + Player* player = (Player*) iplayer; + + player->m_walkingSpeed = 99999.f; } diff --git a/tools/linux/part7_teleport.cpp b/tools/linux/part7_teleport.cpp index e9076b1..d678789 100644 --- a/tools/linux/part7_teleport.cpp +++ b/tools/linux/part7_teleport.cpp @@ -1,57 +1,50 @@ -#include -#include -#include -#include -#include -#include +#include #include "libGameLogic.h" // cd clients/linux_updated/PwnAdventure3_Data/PwnAdventure3/PwnAdventure3/Binaries/Linux -// g++ part7_teleport.cpp -shared -fPIC -std=c++11 -o part7_teleport.so +// g++ part7_teleport.cpp -shared -fPIC -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0 -o part7_teleport.so // LD_PRELOAD=part7_teleport.so ./PwnAdventure3-Linux-Shipping bool frozen = false; Vector3 frozen_pos; -void Player::Chat(const char *msg) { +void Player::Chat(const char *msg) +{ printf("[chat] msg=\"%s\"\n", msg); if(strncmp("tp ", msg, 3) == 0) { Vector3* new_pos = new Vector3(); - sscanf(msg+3, "%f %f %f", &(new_pos->x), &(new_pos->y), &(new_pos->z)); - this->SetPosition(*new_pos); - frozen_pos = this->GetPosition(); + sscanf(&msg[3], "%f %f %f", &new_pos->x, &new_pos->y, &new_pos->z); + SetPosition(*new_pos); + frozen_pos = GetPosition(); } else if(strncmp("tpz ", msg, 4) == 0) { - Vector3 new_pos = this->GetPosition(); - sscanf(msg+4, "%f", &(new_pos.z)); - this->SetPosition(new_pos); - frozen_pos = this->GetPosition(); + Vector3 new_pos = GetPosition(); + sscanf(&msg[4], "%f", &new_pos.z); + SetPosition(new_pos); + frozen_pos = GetPosition(); } else if(strncmp("!", msg, 1) == 0) { - frozen_pos = this->GetPosition(); - if(frozen) frozen = false; - else frozen = true; + frozen_pos = GetPosition(); + frozen = !frozen; } } -bool Player::CanJump() { - return 1; +bool Player::CanJump() +{ + return true; } void World::Tick(float f) { // see libGameLogic.h for the class/object definitions - ClientWorld* world = *((ClientWorld**)(dlsym(RTLD_NEXT, "GameWorld"))); - IPlayer* iplayer = world->m_activePlayer.m_object; - Player* player = ((Player*)(iplayer)); - //Actor* actor = ((Actor*)(iplayer)); - //printf("[LO] IPlayer.GetPlayerName: %s\n", iplayer->GetPlayerName()); - //printf("[LO] player->m_mana: %d\n", player->m_mana); - player->m_walkingSpeed = 99999; - player->m_jumpSpeed = 999; - player->m_jumpHoldTime = 99999; + ClientWorld *world = (ClientWorld *) GameWorld; + IPlayer* iplayer = world->m_activePlayer.Get(); + Player* player = (Player*) iplayer; + + player->m_walkingSpeed = 99999.f; + player->m_jumpSpeed = 999.f; + player->m_jumpHoldTime = 99999.f; if(frozen) { Vector3 vel = player->GetVelocity(); printf("velo: %.2f / %.2f / %.2f\n", vel.x, vel.y, vel.z); player->SetPosition(frozen_pos); - //player->SetVelocity(Vector3(0,0,60)); } } diff --git a/tools/linux/part8_eggs.cpp b/tools/linux/part8_eggs.cpp index 3217b8e..37ac9ed 100644 --- a/tools/linux/part8_eggs.cpp +++ b/tools/linux/part8_eggs.cpp @@ -1,66 +1,59 @@ -#include -#include -#include -#include -#include -#include +#include #include "libGameLogic.h" // cd clients/linux_updated/PwnAdventure3_Data/PwnAdventure3/PwnAdventure3/Binaries/Linux -// g++ part8_eggs.cpp -shared -fPIC -std=c++11 -o part8_eggs.so +// g++ part8_eggs.cpp -shared -fPIC -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0 -o part8_eggs.so // LD_PRELOAD=part8_eggs.so ./PwnAdventure3-Linux-Shipping bool frozen = false; Vector3 frozen_pos; -void Player::Chat(const char *msg) { +void Player::Chat(const char *msg) +{ printf("[chat] msg=\"%s\"\n", msg); if(strncmp("tp ", msg, 3) == 0) { - Vector3 new_pos; - sscanf(msg+3, "%f %f %f", &(new_pos.x), &(new_pos.y), &(new_pos.z)); - this->SetPosition(new_pos); - frozen_pos = this->GetPosition(); + Vector3* new_pos = new Vector3(); + sscanf(&msg[3], "%f %f %f", &new_pos->x, &new_pos->y, &new_pos->z); + SetPosition(*new_pos); + frozen_pos = GetPosition(); } else if(strncmp("tpz ", msg, 4) == 0) { - Vector3 new_pos = this->GetPosition(); - sscanf(msg+4, "%f", &(new_pos.z)); - this->SetPosition(new_pos); - frozen_pos = this->GetPosition(); + Vector3 new_pos = GetPosition(); + sscanf(&msg[4], "%f", &new_pos.z); + SetPosition(new_pos); + frozen_pos = GetPosition(); } else if(strncmp("!", msg, 1) == 0) { - frozen_pos = this->GetPosition(); - if(frozen) frozen = false; - else frozen = true; + frozen_pos = GetPosition(); + frozen = !frozen; } else if(strncmp("actors", msg, 6)==0) { // get the address of the global variable GameWorld - ClientWorld* world = *((ClientWorld**)(dlsym(RTLD_NEXT, "GameWorld"))); + ClientWorld *world = (ClientWorld *) GameWorld; // loop over all actors in the world for (ActorRef _iactor : world->m_actors) { - Actor* actor = ((Actor*)(_iactor.m_object)); + Actor* actor = (Actor*) _iactor.Get(); Vector3 pos = actor->GetPosition(); printf("[actor] %s: %.2f %.2f %.2f\n", actor->GetDisplayName(), pos.x, pos.y, pos.z); } } } -bool Player::CanJump() { - return 1; +bool Player::CanJump() +{ + return true; } void World::Tick(float f) { // see libGameLogic.h for the class/object definitions - ClientWorld* world = *((ClientWorld**)(dlsym(RTLD_NEXT, "GameWorld"))); - IPlayer* iplayer = world->m_activePlayer.m_object; - Player* player = ((Player*)(iplayer)); - //Actor* actor = ((Actor*)(iplayer)); - //printf("[LO] IPlayer.GetPlayerName: %s\n", iplayer->GetPlayerName()); - //printf("[LO] player->m_mana: %d\n", player->m_mana); - player->m_walkingSpeed = 99999; - player->m_jumpSpeed = 999; - player->m_jumpHoldTime = 99999; + ClientWorld *world = (ClientWorld *) GameWorld; + IPlayer* iplayer = world->m_activePlayer.Get(); + Player* player = (Player*) iplayer; + + player->m_walkingSpeed = 99999.f; + player->m_jumpSpeed = 999.f; + player->m_jumpHoldTime = 99999.f; if(frozen) { Vector3 vel = player->GetVelocity(); printf("velo: %.2f / %.2f / %.2f\n", vel.x, vel.y, vel.z); player->SetPosition(frozen_pos); - //player->SetVelocity(Vector3(0,0,60)); } }