diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 250 | ||||
-rw-r--r-- | src/client.cpp | 18 | ||||
-rw-r--r-- | src/gui/beingpopup.cpp | 2 | ||||
-rw-r--r-- | src/gui/chatwindow.cpp | 13 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 3 | ||||
-rw-r--r-- | src/gui/widgets/window.cpp | 16 | ||||
-rw-r--r-- | src/gui/widgets/window.h | 4 | ||||
-rw-r--r-- | src/main.cpp | 11 | ||||
-rw-r--r-- | src/net/tmwa/chathandler.cpp | 14 | ||||
-rw-r--r-- | src/net/tmwa/messagein.cpp | 15 | ||||
-rw-r--r-- | src/net/tmwa/messageout.cpp | 48 | ||||
-rw-r--r-- | src/net/tmwa/messageout.h | 27 | ||||
-rw-r--r-- | src/net/tmwa/network.cpp | 15 | ||||
-rw-r--r-- | src/net/tmwa/network.h | 6 | ||||
-rw-r--r-- | src/utils/specialfolder.cpp | 23 | ||||
-rw-r--r-- | src/utils/specialfolder.h | 5 |
16 files changed, 235 insertions, 235 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 72b44ac6..f993f4ed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,93 +1,87 @@ include(FindPkgConfig) -pkg_check_modules(SDL2 REQUIRED sdl2>=2.0.5 SDL2_image SDL2_mixer SDL2_net SDL2_ttf) -FIND_PACKAGE(PhysFS REQUIRED) -FIND_PACKAGE(CURL REQUIRED) -FIND_PACKAGE(LibXml2 REQUIRED) -FIND_PACKAGE(PNG REQUIRED) -FIND_PACKAGE(Gettext REQUIRED) +pkg_check_modules(SDL2 REQUIRED + sdl2>=2.0.5 + SDL2_image + SDL2_mixer + SDL2_net + SDL2_ttf) +find_package(PhysFS REQUIRED) +find_package(CURL REQUIRED) +find_package(LibXml2 REQUIRED) +find_package(PNG REQUIRED) +find_package(Gettext REQUIRED) +find_package(Intl REQUIRED) -IF (CMAKE_COMPILER_IS_GNUCXX) - # Help getting compilation warnings - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") - IF (WIN32) - # This includes enough debug information to get something useful - # from Dr. Mingw while keeping binary size down. Almost useless - # with gdb, though. - SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -ggdb0 -gstabs2") - ENDIF() -ENDIF() - -SET(FLAGS "-DPACKAGE_VERSION=\\\"${VERSION}\\\"") - -IF (WIN32) - SET(FLAGS "${FLAGS} -DPKG_DATADIR=\\\"${PKG_DATADIR}/\\\"") - SET(FLAGS "${FLAGS} -DLOCALEDIR=\\\"${CMAKE_INSTALL_LOCALEDIR}/\\\"") -ELSE() - SET(FLAGS "${FLAGS} -DPKG_DATADIR=\\\"${CMAKE_INSTALL_FULL_DATAROOTDIR}/mana/\\\"") - SET(FLAGS "${FLAGS} -DLOCALEDIR=\\\"${CMAKE_INSTALL_FULL_LOCALEDIR}/\\\"") -ENDIF() +if(CMAKE_COMPILER_IS_GNUCXX) + # Help getting compilation warnings + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") + if(WIN32) + # This includes enough debug information to get something useful from Dr. + # Mingw while keeping binary size down. Almost useless with gdb, though. + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -ggdb0 -gstabs2") + endif() +endif() -IF (ENABLE_MANASERV) - INCLUDE_DIRECTORIES("../libs/enet/include") - LINK_DIRECTORIES("../libs/enet") - SET(INTERNAL_LIBRARIES enet) +add_compile_definitions(PACKAGE_VERSION="${PROJECT_VERSION}" + $<$<CONFIG:Debug>:DEBUG>) - SET(FLAGS "${FLAGS} -DMANASERV_SUPPORT=1") - MESSAGE(STATUS "Manaserv support enabled") -ENDIF() +if(WIN32) + add_compile_definitions(PKG_DATADIR="${CMAKE_INSTALL_DATADIR}/" + LOCALEDIR="${CMAKE_INSTALL_LOCALEDIR}/") +elseif(NOT APPLE) + add_compile_definitions(PKG_DATADIR="${CMAKE_INSTALL_FULL_DATADIR}/" + LOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}/") +endif() -IF (APPLE OR NOT USE_SYSTEM_GUICHAN) - MESSAGE(STATUS "Using Guichan submodule") - SET(GUICHAN_INCLUDE_DIR "../libs/guichan/include") - SET(GUICHAN_LIBRARIES guichan) - LINK_DIRECTORIES("../libs/guichan") -ELSE() - MESSAGE(STATUS "Using system Guichan") - FIND_PACKAGE(Guichan REQUIRED) -ENDIF() +if(ENABLE_MANASERV) + if(NOT USE_SYSTEM_ENET) + message(STATUS "Using ENet submodule") + set(ENET_INCLUDE_DIR "../libs/enet/include") + set(ENET_LIBRARIES enet) + link_directories("../libs/enet") + else() + message(STATUS "Using system ENet") + find_package(ENet REQUIRED) + endif() -IF (ENABLE_NLS) - SET(FLAGS "${FLAGS} -DENABLE_NLS=1") - MESSAGE(STATUS "i18n support enabled") -ENDIF() + add_compile_definitions(MANASERV_SUPPORT=1) + message(STATUS "Manaserv support enabled") +endif() -IF (CMAKE_BUILD_TYPE) - STRING(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_TOLOWER) - IF(CMAKE_BUILD_TYPE_TOLOWER MATCHES debug OR - CMAKE_BUILD_TYPE_TOLOWER MATCHES relwithdebinfo) - SET(FLAGS "${FLAGS} -DDEBUG") - MESSAGE(STATUS "Set Debug build type") - ENDIF() -ENDIF() +if(APPLE OR NOT USE_SYSTEM_GUICHAN) + message(STATUS "Using Guichan submodule") + set(GUICHAN_INCLUDE_DIR "../libs/guichan/include") + set(GUICHAN_LIBRARIES guichan) + link_directories("../libs/guichan") +else() + message(STATUS "Using system Guichan") + find_package(Guichan REQUIRED) +endif() -IF (WIN32) - SET(EXTRA_LIBRARIES ws2_32 winmm) - FIND_PACKAGE(LibIntl REQUIRED) -ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR BEOS) - FIND_PACKAGE(LibIntl REQUIRED) -ELSEIF (CMAKE_SYSTEM_NAME STREQUAL SunOS) - # explicit linking to libintl is required on Solaris - SET(EXTRA_LIBRARIES intl) -ENDIF() +if(ENABLE_NLS) + add_compile_definitions(ENABLE_NLS=1) + message(STATUS "i18n support enabled") +endif() -IF (WITH_OPENGL) - FIND_PACKAGE(OpenGL REQUIRED) - INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR}) - SET(FLAGS "${FLAGS} -DUSE_OPENGL") - MESSAGE(STATUS "OpenGL support enabled") -ENDIF (WITH_OPENGL) +if(WITH_OPENGL) + find_package(OpenGL REQUIRED) + include_directories(${OPENGL_INCLUDE_DIR}) + add_compile_definitions(USE_OPENGL) + message(STATUS "OpenGL support enabled") +endif(WITH_OPENGL) -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_SOURCE_DIR} - ${SDL2_INCLUDE_DIRS} - ${PNG_INCLUDE_DIR} - ${PHYSFS_INCLUDE_DIR} - ${CURL_INCLUDE_DIR} - ${LIBXML2_INCLUDE_DIR} - ${GUICHAN_INCLUDE_DIR} - ) +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${SDL2_INCLUDE_DIRS} + ${PNG_INCLUDE_DIR} + ${PHYSFS_INCLUDE_DIR} + ${CURL_INCLUDE_DIR} + ${LIBXML2_INCLUDE_DIR} + ${ENET_INCLUDE_DIR} + ${GUICHAN_INCLUDE_DIR} + ${Intl_INCLUDE_DIRS}) -SET(SRCS +set(SRCS gui/widgets/avatarlistbox.cpp gui/widgets/avatarlistbox.h gui/widgets/browserbox.cpp @@ -384,6 +378,8 @@ SET(SRCS utils/physfsrwops.h utils/sha256.cpp utils/sha256.h + utils/specialfolder.cpp + utils/specialfolder.h utils/stringutils.cpp utils/stringutils.h utils/mutex.h @@ -508,10 +504,9 @@ SET(SRCS vector.cpp vector.h video.cpp - video.h - ) + video.h) -SET(SRCS_TMWA +set(SRCS_TMWA net/tmwa/gui/guildtab.cpp net/tmwa/gui/guildtab.h net/tmwa/gui/partytab.cpp @@ -557,10 +552,9 @@ SET(SRCS_TMWA net/tmwa/specialhandler.h net/tmwa/token.h net/tmwa/tradehandler.cpp - net/tmwa/tradehandler.h - ) + net/tmwa/tradehandler.h) -SET(SRCS_MANA +set(SRCS_MANA net/manaserv/adminhandler.cpp net/manaserv/adminhandler.h net/manaserv/beinghandler.cpp @@ -608,49 +602,61 @@ SET(SRCS_MANA net/manaserv/specialhandler.cpp net/manaserv/specialhandler.h net/manaserv/tradehandler.cpp - net/manaserv/tradehandler.h - ) + net/manaserv/tradehandler.h) + +if(WIN32) + configure_file(mana.rc.in mana.rc) + set(SRCS ${SRCS} ${CMAKE_CURRENT_BINARY_DIR}/mana.rc) +endif(WIN32) + +set(APP_ICON_NAME "mana.icns") +set(APP_ICON_FILE "${CMAKE_SOURCE_DIR}/data/icons/${APP_ICON_NAME}") +set_source_files_properties(${APP_ICON_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION + "Resources") -IF (WIN32) - CONFIGURE_FILE(mana.rc.in mana.rc) - SET(SRCS - ${SRCS} - utils/specialfolder.cpp - utils/specialfolder.h - ${CMAKE_CURRENT_BINARY_DIR}/mana.rc - ) -ENDIF (WIN32) +if(ENABLE_MANASERV) + add_executable(mana WIN32 ${SRCS} ${SRCS_MANA} ${SRCS_TMWA} ${APP_ICON_FILE}) +else(ENABLE_MANASERV) + add_executable(mana WIN32 ${SRCS} ${SRCS_TMWA} ${APP_ICON_FILE}) +endif(ENABLE_MANASERV) -SET (PROGRAMS mana) +target_link_libraries( + mana + PRIVATE ${ENET_LIBRARIES} + ${SDL2_LINK_LIBRARIES} + ${PNG_LIBRARIES} + ${PHYSFS_LIBRARY} + ${CURL_LIBRARIES} + ${LIBXML2_LIBRARIES} + ${GUICHAN_LIBRARIES} + ${OPENGL_LIBRARIES} + ${Intl_LIBRARIES}) -IF (ENABLE_MANASERV) - ADD_EXECUTABLE(mana WIN32 ${SRCS} ${SRCS_MANA} ${SRCS_TMWA}) -ELSE(ENABLE_MANASERV) - ADD_EXECUTABLE(mana WIN32 ${SRCS} ${SRCS_TMWA}) -ENDIF(ENABLE_MANASERV) +set_target_properties( + mana + PROPERTIES MACOSX_BUNDLE TRUE + MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME} + MACOSX_BUNDLE_GUI_IDENTIFIER org.manasource.Mana + MACOSX_BUNDLE_ICON_FILE ${APP_ICON_NAME} + MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} + MACOSX_BUNDLE_COPYRIGHT "(C) 2004-2024 ${CPACK_PACKAGE_VENDOR}" + MACOSX_BUNDLE_LONG_VERSION_STRING ${PROJECT_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING + ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}) -TARGET_LINK_LIBRARIES(mana PRIVATE - ${INTERNAL_LIBRARIES} - ${SDL2_LINK_LIBRARIES} - ${PNG_LIBRARIES} - ${PHYSFS_LIBRARY} - ${CURL_LIBRARIES} - ${LIBXML2_LIBRARIES} - ${GUICHAN_LIBRARIES} - ${OPENGL_LIBRARIES} - ${LIBINTL_LIBRARIES} - ${EXTRA_LIBRARIES}) +install( + TARGETS mana + BUNDLE DESTINATION . + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(APPLE) target_link_libraries(mana PRIVATE "-framework Foundation") -endif() - -INSTALL(TARGETS mana RUNTIME DESTINATION ${PKG_BINDIR}) + set_target_properties(mana PROPERTIES OUTPUT_NAME Mana) -IF (CMAKE_SYSTEM_NAME STREQUAL SunOS) - # we expect the SMCgtxt package to be present on Solaris; - # the Solaris gettext is not API-compatible to GNU gettext - SET_TARGET_PROPERTIES(mana PROPERTIES LINK_FLAGS "-L/usr/local/lib") -ENDIF() + set(CPACK_GENERATOR "DRAGNDROP") -SET_TARGET_PROPERTIES(mana PROPERTIES COMPILE_FLAGS "${FLAGS}") + install( + CODE "include(BundleUtilities) + fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/Mana.app\" \"\" \"/usr/local/lib\")" + ) +endif() diff --git a/src/client.cpp b/src/client.cpp index 6e12a579..6fe64b2a 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -70,17 +70,13 @@ #include "utils/gettext.h" #include "utils/mkdir.h" +#include "utils/specialfolder.h" #include "utils/stringutils.h" -#ifdef __APPLE__ -#include <CoreFoundation/CFBundle.h> -#endif - #include <physfs.h> #include <SDL_image.h> #ifdef _WIN32 -#include "utils/specialfolder.h" #include <SDL_syswm.h> #include <winuser.h> #endif @@ -264,17 +260,7 @@ Client::Client(const Options &options): } #if defined __APPLE__ - CFBundleRef mainBundle = CFBundleGetMainBundle(); - CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); - char path[PATH_MAX]; - if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, - PATH_MAX)) - { - fprintf(stderr, "Can't find Resources directory\n"); - } - CFRelease(resourcesURL); - strncat(path, "/data", PATH_MAX - 1); - mPackageDir = path; + mPackageDir = getResourcesLocation() + "/data"; #else mPackageDir = PKG_DATADIR "data"; #endif diff --git a/src/gui/beingpopup.cpp b/src/gui/beingpopup.cpp index c11937e9..7bf9edac 100644 --- a/src/gui/beingpopup.cpp +++ b/src/gui/beingpopup.cpp @@ -51,6 +51,8 @@ BeingPopup::BeingPopup(): add(mBeingName); add(mBeingParty); + + addMouseListener(this); } BeingPopup::~BeingPopup() = default; diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index a3d9a1f4..0229bf76 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -343,10 +343,17 @@ void ChatWindow::mousePressed(gcn::MouseEvent &event) if (event.isConsumed()) return; - mMoved = event.getY() <= getFocused()->getHeight(); - mDragOffsetX = event.getX(); - mDragOffsetY = event.getY(); + // Enable dragging the chat window also in the tab area, since it doesn't + // have much of a title bar. + if (!mouseResize) + { + const int dragHeight = getFocused()->getHeight() + + static_cast<int>(getTitleBarHeight()); + mMoved = event.getY() < dragHeight; + mDragOffsetX = event.getX(); + mDragOffsetY = event.getY(); + } } void ChatWindow::mouseDragged(gcn::MouseEvent &event) diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index f02d2973..0d4af6f8 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -315,9 +315,6 @@ void Viewport::_drawDebugPath(Graphics *graphics) { if (mDebugFlags & Map::DEBUG_MOUSE_PATH) { - // Get the current mouse position - SDL_GetMouseState(&mMouseX, &mMouseY); - // Prepare the walkmask corresponding to the protocol unsigned char walkMask; switch (Net::getNetworkType()) diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index e09986d2..25ca7684 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -371,6 +371,8 @@ void Window::mousePressed(gcn::MouseEvent &event) // Handle window resizing mouseResize = getResizeHandles(event); + if (mouseResize) + mMoved = false; } } @@ -405,12 +407,15 @@ void Window::mouseMoved(gcn::MouseEvent &event) switch (resizeHandles) { case BOTTOM | RIGHT: + case TOP | LEFT: gui->setCursorType(Cursor::RESIZE_DOWN_RIGHT); break; case BOTTOM | LEFT: + case TOP | RIGHT: gui->setCursorType(Cursor::RESIZE_DOWN_LEFT); break; case BOTTOM: + case TOP: gui->setCursorType(Cursor::RESIZE_DOWN); break; case RIGHT: @@ -676,14 +681,17 @@ void Window::adjustPositionAfterResize(int oldScreenWidth, int oldScreenHeight) int Window::getResizeHandles(gcn::MouseEvent &event) { int resizeHandles = 0; - const int y = event.getY(); - if (mGrip && y > (int) mTitleBarHeight) + if (mGrip) { const int x = event.getX(); + const int y = event.getY(); + const int p = getPadding(); + + const bool inPadding = (x < p || x > getWidth() - p) || + (y < p || y > getHeight() - p); - if (!getChildrenArea().isPointInRect(x, y) && - event.getSource() == this) + if (inPadding && event.getSource() == this) { resizeHandles |= (x > getWidth() - resizeBorderWidth) ? RIGHT : (x < resizeBorderWidth) ? LEFT : 0; diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h index ef529a9f..975de335 100644 --- a/src/gui/widgets/window.h +++ b/src/gui/widgets/window.h @@ -349,6 +349,9 @@ class Window : public gcn::Window, gcn::WidgetListener */ static int getGuiAlpha(); + protected: + static int mouseResize; /**< Active resize handles */ + private: enum ResizeHandles { @@ -394,7 +397,6 @@ class Window : public gcn::Window, gcn::WidgetListener int mDefaultWidth; /**< Default window width */ int mDefaultHeight; /**< Default window height */ - static int mouseResize; /**< Active resize handles */ static int instances; /**< Number of Window instances */ Skin *mSkin; /**< Skin in use by this window */ diff --git a/src/main.cpp b/src/main.cpp index 68a6b0c3..935f2d89 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,6 +37,10 @@ #include <winnls.h> #endif +#ifdef __APPLE__ +#include "utils/specialfolder.h" +#endif + static void printHelp() { using std::endl; @@ -213,7 +217,14 @@ static void initInternationalization() #endif // _WIN32 setlocale(LC_MESSAGES, ""); + +#ifdef __APPLE__ + const auto translationsDir = getResourcesLocation() + "/Translations"; + bindtextdomain("mana", translationsDir.c_str()); +#else bindtextdomain("mana", LOCALEDIR); +#endif + bind_textdomain_codeset("mana", "UTF-8"); textdomain("mana"); #endif // ENABLE_NLS diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index 0b111104..a282a943 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -52,6 +52,7 @@ ChatHandler::ChatHandler() SMSG_WHISPER, SMSG_WHISPER_RESPONSE, SMSG_GM_CHAT, + SMSG_SCRIPT_MESSAGE, SMSG_ONLINE_LIST, 0 }; @@ -243,6 +244,19 @@ void ChatHandler::handleMessage(MessageIn &msg) } break; } + + case SMSG_SCRIPT_MESSAGE: + { + chatMsgLength = msg.readInt16() - 5; + if (chatMsgLength <= 0) + break; + + msg.readInt8(); // message type + + SERVER_NOTICE(msg.readString(chatMsgLength)) + break; + } + case SMSG_ONLINE_LIST: { int length = msg.readInt16(); diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp index 899b135d..7c142619 100644 --- a/src/net/tmwa/messagein.cpp +++ b/src/net/tmwa/messagein.cpp @@ -21,7 +21,6 @@ #include "net/tmwa/messagein.h" -#include <SDL.h> #include <SDL_endian.h> #define MAKEWORD(low,high) \ @@ -55,13 +54,8 @@ uint16_t MessageIn::readInt16() uint16_t value = 0; if (mPos + 2 <= mLength) { -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - uint16_t swap; - memcpy(&swap, mData + mPos, sizeof(uint16_t)); - value = SDL_Swap16(swap); -#else memcpy(&value, mData + mPos, sizeof(uint16_t)); -#endif + value = SDL_SwapLE16(value); } mPos += 2; return value; @@ -72,13 +66,8 @@ uint32_t MessageIn::readInt32() uint32_t value = 0; if (mPos + 4 <= mLength) { -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - uint32_t swap; - memcpy(&swap, mData + mPos, sizeof(uint32_t)); - value = SDL_Swap32(swap); -#else memcpy(&value, mData + mPos, sizeof(uint32_t)); -#endif + value = SDL_SwapLE32(value); } mPos += 4; return value; diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp index 19f5ee49..12c9419a 100644 --- a/src/net/tmwa/messageout.cpp +++ b/src/net/tmwa/messageout.cpp @@ -23,54 +23,40 @@ #include "net/tmwa/network.h" -#include <SDL.h> #include <SDL_endian.h> #include <cstring> namespace TmwAthena { -MessageOut::MessageOut(uint16_t id): - mNetwork(TmwAthena::Network::instance()), - mData(mNetwork->mOutBuffer + mNetwork->mOutSize) +MessageOut::MessageOut(uint16_t id) { writeInt16(id); } -void MessageOut::expand(size_t bytes) +char *MessageOut::expand(size_t bytes) { - mNetwork->mOutSize += bytes; + Network &net = *Network::mInstance; + char *data = net.mOutBuffer + net.mOutSize; + net.mOutSize += bytes; + return data; } void MessageOut::writeInt8(uint8_t value) { - expand(1); - mData[mPos] = value; - mPos += 1; + *expand(1) = value; } void MessageOut::writeInt16(uint16_t value) { - expand(2); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - uint16_t swap = SDL_Swap16(value); - memcpy(mData + mPos, &swap, sizeof(uint16_t)); -#else - memcpy(mData + mPos, &value, sizeof(uint16_t)); -#endif - mPos += 2; + value = SDL_SwapLE16(value); + memcpy(expand(sizeof(uint16_t)), &value, sizeof(uint16_t)); } void MessageOut::writeInt32(uint32_t value) { - expand(4); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - uint32_t swap = SDL_Swap32(value); - memcpy(mData + mPos, &swap, sizeof(uint32_t)); -#else - memcpy(mData + mPos, &value, sizeof(uint32_t)); -#endif - mPos += 4; + value = SDL_SwapLE32(value); + memcpy(expand(sizeof(uint32_t)), &value, sizeof(uint32_t)); } void MessageOut::writeString(const std::string &string, int length) @@ -87,24 +73,22 @@ void MessageOut::writeString(const std::string &string, int length) // Make sure the length of the string is no longer than specified stringLength = length; } - expand(length); + + char *data = expand(length); // Write the actual string - memcpy(mData + mPos, string.data(), stringLength); + memcpy(data, string.data(), stringLength); // Pad remaining space with zeros if (length > stringLength) { - memset(mData + mPos + stringLength, '\0', length - stringLength); + memset(data + stringLength, '\0', length - stringLength); } - mPos += length; } void MessageOut::writeCoordinates(uint16_t x, uint16_t y, uint8_t direction) { - char *data = mData + mPos; - expand(3); - mPos += 3; + char *data = expand(3); uint16_t temp = x; temp <<= 6; diff --git a/src/net/tmwa/messageout.h b/src/net/tmwa/messageout.h index 4f1faa9d..b60644de 100644 --- a/src/net/tmwa/messageout.h +++ b/src/net/tmwa/messageout.h @@ -27,8 +27,6 @@ namespace TmwAthena { -class Network; - /** * Used for building an outgoing message to eAthena. * @@ -66,31 +64,12 @@ class MessageOut void writeCoordinates(uint16_t x, uint16_t y, uint8_t direction); - /** - * Returns the content of the message. - */ - char *getData() const { return mData; } - - /** - * Returns the length of the data. - */ - unsigned int getDataSize() const { return mDataSize; } - private: /** - * Expand the packet data to be able to hold more data. - * - * NOTE: For performance enhancements this method could allocate extra - * memory in advance instead of expanding size every time more data is - * added. + * Expand the packet data to be able to hold more data. Returns a + * pointer to the start of the new data. */ - void expand(size_t size); - - Network *mNetwork; - - char *mData; /**< Data building up. */ - unsigned int mDataSize = 0; /**< Size of data. */ - unsigned int mPos = 0; /**< Position in the data. */ + static char *expand(size_t size); }; } // namespace TmwAthena diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index b4ba0b20..a35d7ffe 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -580,11 +580,6 @@ void Network::receive() SDLNet_FreeSocketSet(set); } -Network *Network::instance() -{ - return mInstance; -} - void Network::setError(const std::string &error) { logger->log("Network error: %s", error.c_str()); @@ -592,13 +587,11 @@ void Network::setError(const std::string &error) mState = NET_ERROR; } -Uint16 Network::readWord(int pos) +uint16_t Network::readWord(int pos) { -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - return SDL_Swap16((*(Uint16*)(mInBuffer+(pos)))); -#else - return (*(Uint16*)(mInBuffer+(pos))); -#endif + uint16_t value; + memcpy(&value, mInBuffer + pos, sizeof(uint16_t)); + return SDL_SwapLE16(value); } } // namespace TmwAthena diff --git a/src/net/tmwa/network.h b/src/net/tmwa/network.h index 36d8cafd..4069f916 100644 --- a/src/net/tmwa/network.h +++ b/src/net/tmwa/network.h @@ -90,15 +90,13 @@ class Network NET_ERROR }; - protected: + private: friend int networkThread(void *data); friend class MessageOut; - static Network *instance(); - void setError(const std::string &error); - Uint16 readWord(int pos); + uint16_t readWord(int pos); bool realConnect(); diff --git a/src/utils/specialfolder.cpp b/src/utils/specialfolder.cpp index c351ba1a..c882534d 100644 --- a/src/utils/specialfolder.cpp +++ b/src/utils/specialfolder.cpp @@ -18,8 +18,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifdef _WIN32 #include "specialfolder.h" + +#ifdef _WIN32 #include <windows.h> #include <stdlib.h> @@ -74,4 +75,22 @@ int main() << std::endl; } #endif -#endif +#endif // _WIN32 + +#ifdef __APPLE__ +#include <CoreFoundation/CFBundle.h> + +std::string getResourcesLocation() +{ + CFBundleRef mainBundle = CFBundleGetMainBundle(); + CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); + char path[PATH_MAX]; + if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, + PATH_MAX)) + { + fprintf(stderr, "Can't find Resources directory\n"); + } + CFRelease(resourcesURL); + return path; +} +#endif // __APPLE__ diff --git a/src/utils/specialfolder.h b/src/utils/specialfolder.h index 8570d009..36a4e0c1 100644 --- a/src/utils/specialfolder.h +++ b/src/utils/specialfolder.h @@ -27,4 +27,9 @@ std::string getSpecialFolderLocation(const KNOWNFOLDERID &folderId); #endif +#ifdef __APPLE__ +#include <string> +std::string getResourcesLocation(); +#endif + #endif |