// *************************************************************** // Function: PacketMan.cpp // *************************************************************** #include "PacketMan.h" #include "Log.h" //Constructor PacketMan::PacketMan(){} //Deconstructor PacketMan::~PacketMan() { for (unsigned int i=0; i0) mPackets.clear(); } //************************************ // Name: DirBack // // Moves the active directory up one level. // // Parameters: // // Return: // 0 - no errors // -1 - Active directory name corrupt //************************************ int PacketMan::DirBack() { //count how many '/' are in the string int count=0; for (unsigned int i=0; i2) { char* pLoc=strchr(mActiveDir, '/'); *pLoc=0; pLoc=strchr(mActiveDir, '/'); *pLoc=0; return 0; } return -1; } //************************************ // Name: DirSwitch // // Change active directory to specified directory. // // Parameters: // directory - Active directory // // Return: // - zero //************************************ int PacketMan::DirSwitch(char* directory) { assert(directory!=NULL); strcpy(mActiveDir, directory); return 0; } //************************************ // Name: Load // // Loads all packets within the path. // // Parameters: // pPath - Directory path // // Return: // 0 - no errors // -1 - failed to load packets //************************************ int PacketMan::Load(char* pPath) { assert(pPath!=NULL); if (LoadPackets(pPath)!=0) { gCoreLog.LOCATION; gCoreLog.error("Failed to load packets!"); return -1; } return 0; } //Useless function now int PacketMan::Init() { return 0; } //************************************ // Name: GetData // // Gets a pointer to the requested data. // // Parameters: // pPacketName - Packet name string // pDsize - Buffer for size of packet // // Return: // - Pointer to requested packet's data. //************************************ unsigned char* PacketMan::GetData(char* pPacketName, short* pDsize) { assert(pPacketName!=NULL); assert(pDsize!=NULL); for (unsigned int i=0; inumbytes) { pTemp=new BYTE[numbytes]; ds=numbytes; } else { pTemp=new BYTE[mPackets[i].dataPartBytes]; ds=mPackets[i].dataPartBytes; } memcpy(pTemp, mPackets[i].pData+mPackets[i].data, ds); mPackets[i].data+=ds; mPackets[i].pDataPart=pTemp; mPackets[i].dataPartBytes-=ds; *pDSize=ds; return (unsigned char*)pTemp; } } } return NULL; }