diff --git a/src/Client/DefScript/TypeStorage.h b/src/Client/DefScript/TypeStorage.h index 94d7163..d42915a 100644 --- a/src/Client/DefScript/TypeStorage.h +++ b/src/Client/DefScript/TypeStorage.h @@ -7,6 +7,8 @@ template class TypeStorage { public: + typedef typename std::map _TypeMap; + typedef typename _TypeMap::iterator _TypeIter; TypeStorage() { _keep = false; } ~TypeStorage(); bool Exists(std::string); @@ -25,7 +27,7 @@ public: private: T *_Create(std::string); - std::map _storage; + _TypeMap _storage; bool _keep; }; @@ -46,7 +48,7 @@ template T *TypeStorage::_Create(std::string s) // delete object with that name, if present template void TypeStorage::Delete(std::string s) { - std::map::iterator it = _storage.find(s); + _TypeIter it = _storage.find(s); if(it != _storage.end()) { delete it->second; @@ -57,7 +59,7 @@ template void TypeStorage::Delete(std::string s) // delete object with that ptr, if present template void TypeStorage::DeleteByPtr(T *ptr) { - for(std::map::iterator it = _storage.begin(); it != _storage.end(); it++) + for(_TypeIter it = _storage.begin(); it != _storage.end(); it++) { if(it->second == ptr) { @@ -71,7 +73,7 @@ template void TypeStorage::DeleteByPtr(T *ptr) // return the the object with that name. return NULL if not found template T *TypeStorage::GetNoCreate(std::string s) { - std::map::iterator it = _storage.find(s); + _TypeIter it = _storage.find(s); if(it != _storage.end()) return it->second; return NULL; @@ -97,7 +99,7 @@ template void TypeStorage::Clear(bool keep) _storage.clear(); return; } - for(std::map::iterator it = _storage.begin(); it != _storage.end();) + for(_TypeIter it = _storage.begin(); it != _storage.end();) { delete it->second; _storage.erase(it++); @@ -121,7 +123,7 @@ template void TypeStorage::Unlink(std::string s) // removes the pointer from the storage without deleting it, if name is unknown template void TypeStorage::UnlinkByPtr(T *ptr) { - for(std::map::iterator it = _storage.begin(); it != _storage.end();) + for(_TypeIter it = _storage.begin(); it != _storage.end();) { if(it->second == ptr) { @@ -133,7 +135,7 @@ template void TypeStorage::UnlinkByPtr(T *ptr) template std::string TypeStorage::GetNameByPtr(T *ptr) { - for(std::map::iterator it = _storage.begin(); it != _storage.end();) + for(_TypeIter it = _storage.begin(); it != _storage.end();) { if(it->second == ptr) { diff --git a/src/Client/PseuWoW.cpp b/src/Client/PseuWoW.cpp index ca945a4..20a90ff 100644 --- a/src/Client/PseuWoW.cpp +++ b/src/Client/PseuWoW.cpp @@ -89,12 +89,10 @@ PseuInstance::~PseuInstance() delete _conf; log("--- Instance shut down ---"); - log_close(); } bool PseuInstance::Init(void) { - log_prepare("logfile.txt","a"); log_setloglevel(0); log(""); log("--- Initializing Instance ---"); diff --git a/src/Client/Realm/RealmSession.cpp b/src/Client/Realm/RealmSession.cpp index 6139826..e0442f5 100644 --- a/src/Client/Realm/RealmSession.cpp +++ b/src/Client/Realm/RealmSession.cpp @@ -495,7 +495,7 @@ void RealmSession::_HandleLogonChallenge(ByteBuffer& pkt) void RealmSession::_HandleLogonProof(ByteBuffer& pkt) { - logdebug("RealmSocket: Got AUTH_LOGON_PROOF [%u of %u bytes]\n",pkt.size(),26); + logdebug("RealmSocket: Got AUTH_LOGON_PROOF [%u of %u bytes]",pkt.size(),26); if(pkt.size() < 2) { logerror("AUTH_LOGON_PROOF: Recieved incorrect/unknown packet. Hexdump:"); diff --git a/src/Client/World/MovementMgr.cpp b/src/Client/World/MovementMgr.cpp new file mode 100644 index 0000000..ec38992 --- /dev/null +++ b/src/Client/World/MovementMgr.cpp @@ -0,0 +1,171 @@ +#include "PseuWoW.h" +#include "WorldSession.h" +#include "World.h" +#include "MovementMgr.h" +#include "Player.h" + +MovementMgr::MovementMgr() +{ + _moveFlags = 0; + _instance = NULL; + _optime = 0; + _updatetime = 0; +} + +MovementMgr::~MovementMgr() +{ +} + +void MovementMgr::SetInstance(PseuInstance *inst) +{ + _movemode = MOVEMODE_MANUAL; + _instance = inst; + _mychar = inst->GetWSession()->GetMyChar(); +} + +void MovementMgr::_BuildPacket(uint16 opcode) +{ + WorldPacket wp(opcode,4+1+4+12); // it can be larger, if we are juming, on transport or swimming + wp << _moveFlags; + wp << (uint8)0; // unk + wp << getMSTime(); + wp << _mychar->GetPosition(); + // TODO: transport not yet handled/done + if(_moveFlags & MOVEMENTFLAG_ONTRANSPORT) + { + wp << (uint64)0; // transport guid + wp << WorldPosition(); // transport position + wp << getMSTime(); // transport time (??) + } + // TODO: swimming not yet done + if(_moveFlags & MOVEMENTFLAG_SWIMMING) + { + wp << (float)0; // angle; 1.55=looking up, -1.55=looking down, 0=looking forward + } + wp << (uint32)0; // last fall time (also used when jumping) + // TODO: jumping not yet done + // TODO: spline not yet done + + + _optime = getMSTime(); + +} + +void MovementMgr::Update(bool calcpos) +{ + uint32 curtime = getMSTime(); + uint32 timediff = curtime - _updatetime; + _updatetime = curtime; + + if(_movemode == MOVEMODE_AUTO) + { + WorldPosition& pos = _mychar->GetPosition(); + float turnspeed = _mychar->GetSpeed(MOVE_TURN) / 1000.0f * timediff; + float runspeed = _mychar->GetSpeed(MOVE_RUN) / 1000.0f * timediff; + float movespeed = runspeed; // or use walkspeed, depending on setting. for now use only runspeed + // TODO: calc other speeds as soon as implemented + + /* + if(_moveFlags & MOVEMENTFLAG_FORWARD) + { + pos.x += movespeed * sin(pos.o); + pos.y += movespeed * cos(pos.o); + } + // ... + if(_moveFlags & MOVEMENTFLAG_LEFT) + { + pos.o -= turnspeed; + } + if(_moveFlags & MOVEMENTFLAG_RIGHT) + { + pos.o += turnspeed; + } + if(pos.o < 0) + pos.o += 2 * M_PI; + else if(pos.o > 2 * M_PI) + pos.o -= 2 * M_PI; + + pos.z = _instance->GetWSession()->GetWorld()->GetPosZ(pos.x,pos.y); + */ + // ^ It should look like this later on, but its not finished, and formulas are not tested. + // see it as some future plans that need a lot of finetuning ;) + } + + // if we are moving, and 500ms have passed, send an heartbeat packet + if( (_moveFlags & MOVEMENTFLAG_ANY_MOVE) && _optime + MOVE_HEARTBEAT_DELAY < getMSTime()) + { + _BuildPacket(MSG_MOVE_HEARTBEAT); + } + + // TODO: apply gravity, handle falling, swimming, etc. +} + +void MovementMgr::MoveStop(void) +{ + _moveFlags &= ~(MOVEMENTFLAG_ANY_MOVE); + Update(false); + _BuildPacket(MSG_MOVE_STOP); +} + +void MovementMgr::MoveStartForward(void) +{ + _moveFlags |= MOVEMENTFLAG_FORWARD; + _moveFlags &= ~MOVEMENTFLAG_BACKWARD; + Update(false); + _BuildPacket(MSG_MOVE_START_FORWARD); +} + +void MovementMgr::MoveStartBackward(void) +{ + _moveFlags |= MOVEMENTFLAG_BACKWARD; + _moveFlags &= ~MOVEMENTFLAG_FORWARD; + Update(false); + _BuildPacket(MSG_MOVE_START_BACKWARD); +} + +void MovementMgr::MoveStartStrafeLeft(void) +{ + _moveFlags |= MOVEMENTFLAG_STRAFE_LEFT; + _moveFlags &= ~MOVEMENTFLAG_STRAFE_RIGHT; + Update(false); + _BuildPacket(MSG_MOVE_START_STRAFE_LEFT); +} + +void MovementMgr::MoveStartStrafeRight(void) +{ + _moveFlags |= MOVEMENTFLAG_STRAFE_RIGHT; + _moveFlags &= ~MOVEMENTFLAG_STRAFE_LEFT; + Update(false); + _BuildPacket(MSG_MOVE_START_STRAFE_RIGHT); +} + +void MovementMgr::MoveStartTurnLeft(void) +{ + _moveFlags |= MOVEMENTFLAG_LEFT; + _moveFlags &= ~MOVEMENTFLAG_RIGHT; + Update(false); + _BuildPacket(MSG_MOVE_START_TURN_LEFT); +} + +void MovementMgr::MoveStartTurnRight(void) +{ + _moveFlags |= MOVEMENTFLAG_RIGHT; + _moveFlags &= ~MOVEMENTFLAG_LEFT; + Update(false); + _BuildPacket(MSG_MOVE_START_TURN_RIGHT); +} + +void MovementMgr::MoveStopTurn(void) +{ + _moveFlags &= ~(MOVEMENTFLAG_LEFT | MOVEMENTFLAG_RIGHT); + Update(false); + _BuildPacket(MSG_MOVE_STOP_TURN); +} + +void MovementMgr::MoveSetFacing(float o) +{ + _mychar->SetPosition(_mychar->GetX(), _mychar->GetY(), _mychar->GetZ(), o); + Update(true); + _BuildPacket(MSG_MOVE_SET_FACING); +} + diff --git a/src/Client/World/MovementMgr.h b/src/Client/World/MovementMgr.h new file mode 100644 index 0000000..a1255a1 --- /dev/null +++ b/src/Client/World/MovementMgr.h @@ -0,0 +1,85 @@ +#ifndef MOVEMENTMGR_H +#define MOVEMENTMGR_H + +#include "common.h" + +#define MOVE_HEARTBEAT_DELAY 500 + +enum MovementFlags +{ + MOVEMENTFLAG_NONE = 0x00000000, + MOVEMENTFLAG_FORWARD = 0x00000001, + MOVEMENTFLAG_BACKWARD = 0x00000002, + MOVEMENTFLAG_STRAFE_LEFT = 0x00000004, + MOVEMENTFLAG_STRAFE_RIGHT = 0x00000008, + MOVEMENTFLAG_LEFT = 0x00000010, + MOVEMENTFLAG_RIGHT = 0x00000020, + MOVEMENTFLAG_PITCH_UP = 0x00000040, + MOVEMENTFLAG_PITCH_DOWN = 0x00000080, + MOVEMENTFLAG_WALK = 0x00000100, + MOVEMENTFLAG_ONTRANSPORT = 0x00000200, + MOVEMENTFLAG_UNK1 = 0x00000400, + MOVEMENTFLAG_FLY_UNK1 = 0x00000800, + MOVEMENTFLAG_JUMPING = 0x00001000, + MOVEMENTFLAG_UNK4 = 0x00002000, + MOVEMENTFLAG_FALLING = 0x00004000, + // 0x8000, 0x10000, 0x20000, 0x40000, 0x80000, 0x100000 + MOVEMENTFLAG_SWIMMING = 0x00200000, // appears with fly flag also + MOVEMENTFLAG_FLY_UP = 0x00400000, + MOVEMENTFLAG_CAN_FLY = 0x00800000, + MOVEMENTFLAG_FLYING = 0x01000000, + MOVEMENTFLAG_UNK5 = 0x02000000, + MOVEMENTFLAG_SPLINE = 0x04000000, // probably wrong name + MOVEMENTFLAG_SPLINE2 = 0x08000000, + MOVEMENTFLAG_WATERWALKING = 0x10000000, + MOVEMENTFLAG_SAFE_FALL = 0x20000000, // active rogue safe fall spell (passive) + MOVEMENTFLAG_UNK3 = 0x40000000, + + // custom flags + MOVEMENTFLAG_ANY_MOVE = (MOVEMENTFLAG_BACKWARD | MOVEMENTFLAG_FORWARD | MOVEMENTFLAG_STRAFE_LEFT | MOVEMENTFLAG_STRAFE_RIGHT + | MOVEMENTFLAG_LEFT | MOVEMENTFLAG_RIGHT) +}; + +enum MoveModes +{ + MOVEMODE_AUTO, // CPU controlling movement, MyCharacter must be updated + MOVEMODE_MANUAL, // user controlling movement, MyCharacter is updated by the GUI already +}; + +class PseuInstance; +class MyCharacter; + + +class MovementMgr +{ +public: + MovementMgr(); + ~MovementMgr(); + void SetInstance(PseuInstance*); + inline void SetMoveMode(uint8 mode) { _movemode = mode; } + void Update(bool); + void MoveStartForward(void); + void MoveStartBackward(void); + void MoveStop(void); + void MoveStartStrafeLeft(void); + void MoveStartStrafeRight(void); + void MoveStartTurnLeft(void); + void MoveStartTurnRight(void); + void MoveStopTurn(void); + void MoveFallLand(void); + void MoveSetFacing(float); + +private: + void _BuildPacket(uint16); + PseuInstance *_instance; + MyCharacter *_mychar; + uint32 _moveFlags; // server relevant flags (move forward/backward/swim/fly/jump/etc) + uint32 _updatetime; // timeMS of last update cycle + uint32 _optime; // timeMS when last opcode was sent + uint8 _movemode; // automatic or manual + UnitMoveType _movetype; // index used for speed selection + + +}; + +#endif \ No newline at end of file diff --git a/src/Client/World/World.h b/src/Client/World/World.h index 79a66fe..d1ba178 100644 --- a/src/Client/World/World.h +++ b/src/Client/World/World.h @@ -13,6 +13,17 @@ struct WorldPosition float x,y,z,o; }; +inline ByteBuffer& operator<<(ByteBuffer& bb, WorldPosition& p) +{ + bb << p.x << p.y << p.z << p.o; + return bb; +} +inline ByteBuffer& operator>>(ByteBuffer& bb, WorldPosition& p) +{ + bb >> p.x >> p.y >> p.z >> p.o; + return bb; +} + // used as interface for movement, map data, class World { diff --git a/src/Client/World/WorldSession.cpp b/src/Client/World/WorldSession.cpp index 03aac78..ac707c5 100644 --- a/src/Client/World/WorldSession.cpp +++ b/src/Client/World/WorldSession.cpp @@ -459,7 +459,7 @@ void WorldSession::_HandleCharEnumOpcode(WorldPacket& recvPacket) return; } - logdetail("Chars in list: %u\n",num); + logdetail("Chars in list: %u",num); _LoadCache(); // we are about to login, so we need cache data for(unsigned int i=0;i + + + + diff --git a/src/PseuWoW_VC80.vcproj b/src/PseuWoW_VC80.vcproj index d56f482..a44ebd4 100644 --- a/src/PseuWoW_VC80.vcproj +++ b/src/PseuWoW_VC80.vcproj @@ -417,6 +417,14 @@ RelativePath=".\Client\World\Item.h" > + + + + diff --git a/src/shared.vcproj b/src/shared.vcproj index 6afe262..7bccfdb 100644 --- a/src/shared.vcproj +++ b/src/shared.vcproj @@ -153,6 +153,9 @@ + + diff --git a/src/shared/ByteBuffer.h b/src/shared/ByteBuffer.h index 3c15192..6a20b16 100644 --- a/src/shared/ByteBuffer.h +++ b/src/shared/ByteBuffer.h @@ -22,6 +22,7 @@ #include #include #include +#include class ByteBufferException { diff --git a/src/shared/SysDefs.h b/src/shared/SysDefs.h index 64aee9b..f3f18cb 100644 --- a/src/shared/SysDefs.h +++ b/src/shared/SysDefs.h @@ -71,21 +71,70 @@ #define I64FMT "%016llX" #define I64FMTD "%llu" #define SI64FMTD "%lld" - typedef __int64_t int64; - typedef __int32_t int32; - typedef __int16_t int16; - typedef __int8_t int8; - typedef __uint64_t uint64; - typedef __uint32_t uint32; - typedef __uint16_t uint16; - typedef __uint8_t uint8; - typedef uint16 WORD; - typedef uint32 DWORD; +# if PLATFORM == PLATFORM_UNIX + typedef __int64_t int64; + typedef __int32_t int32; + typedef __int16_t int16; + typedef __int8_t int8; + typedef __uint64_t uint64; + typedef __uint32_t uint32; + typedef __uint16_t uint16; + typedef __uint8_t uint8; + typedef uint16 WORD; + typedef uint32 DWORD; +# else + typedef long long int64; + typedef long int32; + typedef short int16; + typedef char int8; + typedef unsigned long long uint64; + typedef unsigned long uint32; + typedef unsigned short uint16; + typedef unsigned char uint8; + typedef unsigned short WORD; + typedef uint32 DWORD; +# endif #endif #ifndef SIGQUIT #define SIGQUIT 3 #endif +#if COMPILER == COMPILER_MICROSOFT +# if _MSC_VER >= 1500 +# define COMPILER_NAME "VC90" +# elif _MSC_VER >= 1400 +# define COMPILER_NAME "VC80" +# elif _MSC_VER >= 1310 +# define COMPILER_NAME "VC71" +# endif +# define COMPILER_VERSION _MSC_VER +# define COMPILER_VERSION_OUT "%u" +#elif COMPILER == COMPILER_GNU +# define COMPILER_NAME "GCC" +# ifdef __GNUC_PATCHLEVEL__ +# define COMPILER_VERSION STRINGIZE(__GNUC__) "." STRINGIZE(__GNUC_MINOR__) "." STRINGIZE(__GNUC_PATCHLEVEL__) +# else +# define COMPILER_VERSION STRINGIZE(__GNUC__) "." STRINGIZE(__GNUC_MINOR__) +# endif +# define COMPILER_VERSION_OUT "%s" +// TODO: add more compilers here when necessary +#else +# define COMPILER_NAME "unknown" +# define COMPILER_VERSION "unk" +# define COMPILER_VERSION_OUT "%s" +#endif -#endif \ No newline at end of file +#if PLATFORM == PLATFORM_UNIX +# define PLATFORM_NAME "Unix" +#elif PLATFORM == PLATFORM_WIN32 +# define PLATFORM_NAME "Win32" +#elif PLATFORM == PLATFORM_APPLE +# define PLATFORM_NAME "Apple" +// TODO: add more platforms here when necessary +#else +# define PLATFORM_NAME "unknown" +#endif + + +#endif diff --git a/src/shared/Widen.h b/src/shared/Widen.h new file mode 100644 index 0000000..52ccf19 --- /dev/null +++ b/src/shared/Widen.h @@ -0,0 +1,45 @@ +#ifndef _WIDEN_H +#define _WIDEN_H + +#include +#include +#include +#include +#include + +// Put this class in your personal toolbox... +template, +class A = std::allocator > + +class Widen : public std::unary_function< + const std::string&, std::basic_string > +{ + std::locale loc_; + const std::ctype* pCType_; + + // No copy-constructor, no assignment operator... + Widen(const Widen&); + Widen& operator= (const Widen&); + +public: + // Constructor... + Widen(const std::locale& loc = std::locale()) : loc_(loc) + { + pCType_ = &std::use_facet >(loc); + } + + // Conversion... + std::basic_string operator() (const std::string& str) const + { + typename std::basic_string::size_type srcLen = + str.length(); + const char* pSrcBeg = str.c_str(); + std::vector tmp(srcLen); + + pCType_->widen(pSrcBeg, pSrcBeg + srcLen, &tmp[0]); + return std::basic_string(&tmp[0], srcLen); + } +}; + +#endif diff --git a/src/shared/common.h b/src/shared/common.h index 092d034..54783fa 100644 --- a/src/shared/common.h +++ b/src/shared/common.h @@ -23,8 +23,11 @@ # include "zthread/Thread.h" #endif +#define STRINGIZE(a) #a + #include "SysDefs.h" #include "DebugStuff.h" +#include "Widen.h" #include "tools.h" #include "log.h" diff --git a/src/shared/log.cpp b/src/shared/log.cpp index 3851c80..37d92d2 100644 --- a/src/shared/log.cpp +++ b/src/shared/log.cpp @@ -14,6 +14,11 @@ void log_prepare(char *fn, char *mode = NULL) { if(!mode) mode = "a"; + if(logfile) + { + fflush(logfile); + fclose(logfile); + } logfile = fopen(fn,mode); }