From c549192f590066782f7f97f0d5a7137d6178f52c Mon Sep 17 00:00:00 2001 From: Raymonf Date: Thu, 20 Aug 2020 15:59:54 -0400 Subject: [PATCH 01/18] CMake build support (#8) * CMake build support * Make things nice for VS users Co-authored-by: Raymonf --- .gitignore | 3 +++ CMakeLists.txt | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 CMakeLists.txt diff --git a/.gitignore b/.gitignore index 8e9237c..ad152dc 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ config.ini *.o tags *~ +CMakeFiles/ +CMakeCache.txt +build/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..cd30f33 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 3.16) +project(OpenFusion) + +set(CMAKE_CXX_STANDARD 17) + +# Disallow in-source builds +if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) + message(FATAL_ERROR "In-source builds not allowed. Please refer to the wiki for more information. Please remove the CMakeFiles folder and the CMakeCache.txt file.") +endif() + +# Output binaries to the bin folder in the source directory +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) + +# Put CMake targets (ALL_BUILD/ZERO_CHECK) into a folder +set_property(GLOBAL PROPERTY USE_FOLDERS ON) + +# Set the OpenFusion project as the default startup project for VS +set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT openfusion) + +include_directories(src) + +file(GLOB_RECURSE SOURCES src/**.cpp src/**.hpp) + +add_executable(openfusion ${SOURCES}) + +# Set the output binary name to winfusion to match the regular Makefile +set_target_properties(openfusion PROPERTIES OUTPUT_NAME winfusion) From 09b21c54d33ad6fe9ebed42e15f0e24febb50a73 Mon Sep 17 00:00:00 2001 From: Raymonf Date: Thu, 20 Aug 2020 16:10:29 -0400 Subject: [PATCH 02/18] Update compilation instructions --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c6dca65..0c7610d 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,15 @@ Some modern IDEs/text editors do this automatically. If all else fails, use Note ## Compiling -OpenFusion can be compiled from source using the included makefile. A detailed compilation guide is available for Windows users [in the wiki](https://github.com/OpenFusionProject/OpenFusion/wiki/Compilation-on-Windows). Otherwise, to compile it for the current platform you're on, just run `make` with the correct build tools installed (currently make and clang). +You have two choices for compiling OpenFusion: the included Makefile and the included CMakeLists file. + +### Makefile + +A detailed compilation guide is available for Windows users in the wiki [using MinGW-w64 and MSYS2](https://github.com/OpenFusionProject/OpenFusion/wiki/Compilation-on-Windows). Otherwise, to compile it for the current platform you're on, just run `make` with the correct build tools installed (currently make and clang). + +### CMake + +A detailed guide is available [in the wiki](https://github.com/OpenFusionProject/OpenFusion/wiki/Compilation-with-CMake-or-Visual-Studio) for people using regular old CMake or the version of CMake that comes with Visual Studio. tl;dr: `cmake -B build` ## "Gameplay" From 7f8e7dfa1ccd3fa406208b3239d8831d3c7d39e0 Mon Sep 17 00:00:00 2001 From: Raymonf Date: Thu, 20 Aug 2020 16:17:53 -0400 Subject: [PATCH 03/18] Use regular old MIT license --- LICENSE.md | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index db54105..541618c 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,9 +1,21 @@ -The OpenFusion MIT except Malorn License +MIT License -Copyright 2020 Seth Stubbs +Copyright (c) 2020 Seth Stubbs -Excluding the individual known as "MalornWS" and their associates, permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. -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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +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 AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From c827b5a1b6dad762faf0d2cd70a99ec224619562 Mon Sep 17 00:00:00 2001 From: Raymonf Date: Thu, 20 Aug 2020 17:21:43 -0400 Subject: [PATCH 04/18] Lower CMake version requirement to 3.13 Technically we could probably move this all the way down to 3.6, but 3.13 should be a good version to target. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd30f33..e02ae6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.16) +cmake_minimum_required(VERSION 3.13) project(OpenFusion) set(CMAKE_CXX_STANDARD 17) From 6857f50c3023b790fae2336a7f3b2770b4a03032 Mon Sep 17 00:00:00 2001 From: CPunch Date: Thu, 20 Aug 2020 16:43:48 -0500 Subject: [PATCH 05/18] added basic NPCManager --- config.ini | 4 +-- src/CNShardServer.hpp | 2 ++ src/NPC.hpp | 26 ++++++++++++++++++ src/NPCManager.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++- src/NPCManager.hpp | 5 +++- src/PlayerManager.cpp | 3 +++ src/PlayerManager.hpp | 1 + src/main.cpp | 2 ++ 8 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 src/NPC.hpp diff --git a/config.ini b/config.ini index bd72bbc..1df6030 100644 --- a/config.ini +++ b/config.ini @@ -4,7 +4,7 @@ port=8001 # enables two randomly generated characters in the # character selection menu for convenience -randomcharacters=false +randomcharacters=true # Shard Server configuration [shard] @@ -12,7 +12,7 @@ port=8002 # you'll want to change this one ip=192.168.1.183 # distance at which other players and NPCs become visible -view=20000 +view=1000 # little message players see when they enter the game motd=Welcome to OpenFusion! diff --git a/src/CNShardServer.hpp b/src/CNShardServer.hpp index fd83cef..2f69e73 100644 --- a/src/CNShardServer.hpp +++ b/src/CNShardServer.hpp @@ -40,6 +40,8 @@ enum SHARDPACKETID { P_FE2CL_PC_ZIPLINE = 822083703, P_FE2CL_PC_MOVEPLATFORM = 822083704, P_FE2CL_PC_SLOPE = 822083705, + P_FE2CL_NPC_ENTER = 822083595, + P_FE2CL_NPC_EXIT = 822083596, P_FE2CL_REP_PC_GOTO_SUCC = 822083633, P_FE2CL_GM_REP_PC_SET_VALUE = 822083781, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC = 822083602, diff --git a/src/NPC.hpp b/src/NPC.hpp new file mode 100644 index 0000000..f467040 --- /dev/null +++ b/src/NPC.hpp @@ -0,0 +1,26 @@ +#ifndef _NPCCLASS_HPP +#define _NPCCLASS_HPP + +#include "CNStructs.hpp" + +class BaseNPC { +public: + sNPCAppearanceData appearanceData; + + BaseNPC() {}; + BaseNPC(int x, int y, int z, int type) { + appearanceData.iX = x; + appearanceData.iY = y; + appearanceData.iZ = z; + appearanceData.iNPCType = type; + appearanceData.iHP = 400; + appearanceData.iAngle = 0; + appearanceData.iConditionBitFlag = 0; + appearanceData.iBarkerType = 0; + + // hopefully no collisions happen :eyes: + appearanceData.iNPC_ID = (int32_t)getTime(); + }; +}; + +#endif \ No newline at end of file diff --git a/src/NPCManager.cpp b/src/NPCManager.cpp index 1b08f75..b8d6c15 100644 --- a/src/NPCManager.cpp +++ b/src/NPCManager.cpp @@ -1,5 +1,64 @@ #include "NPCManager.hpp" +#include "settings.hpp" + +#include +#include +#include + +std::map NPCManager::NPCs; void NPCManager::init() { - + /* BaseNPC test(settings::SPAWN_X, settings::SPAWN_Y, settings::SPAWN_Z, 727); + NPCs[test.appearanceData.iNPC_ID] = test; */ +} + +void NPCManager::updatePlayerNPCS(CNSocket* sock, PlayerView& view) { + std::list yesView; + std::list noView; + + for (auto pair : NPCs) { + int diffX = abs(view.plr.x - pair.second.appearanceData.iX); + int diffY = abs(view.plr.y - pair.second.appearanceData.iY); + + if (diffX < settings::VIEWDISTANCE && diffY < settings::VIEWDISTANCE) { + yesView.push_back(pair.first); + } else { + noView.push_back(pair.first); + } + } + + std::list::iterator i = view.viewableNPCs.begin(); + while (i != view.viewableNPCs.end()) { + int32_t id = *i; + + if (std::find(noView.begin(), noView.end(), id) != noView.end()) { + // it shouldn't be visible, send NPC_EXIT + sP_FE2CL_NPC_EXIT* exitData = (sP_FE2CL_NPC_EXIT*)xmalloc(sizeof(sP_FE2CL_NPC_EXIT)); + + exitData->iNPC_ID = id; + + sock->sendPacket(new CNPacketData((void*)exitData, P_FE2CL_NPC_EXIT, sizeof(sP_FE2CL_NPC_EXIT), sock->getFEKey())); + + // remove from view + view.viewableNPCs.erase(i++); + } + + ++i; + } + + for (int32_t id : yesView) { + if (std::find(view.viewableNPCs.begin(), view.viewableNPCs.end(), id) == view.viewableNPCs.end()) { + + // needs to be added to viewableNPCs! send NPC_ENTER + sP_FE2CL_NPC_ENTER* enterData = (sP_FE2CL_NPC_ENTER*)xmalloc(sizeof(sP_FE2CL_NPC_ENTER)); + + enterData->NPCAppearanceData = NPCs[id].appearanceData; + + sock->sendPacket(new CNPacketData((void*)enterData, P_FE2CL_NPC_ENTER, sizeof(sP_FE2CL_NPC_ENTER), sock->getFEKey())); + + view.viewableNPCs.push_back(id); + } + } + + PlayerManager::players[sock].viewableNPCs = view.viewableNPCs; } \ No newline at end of file diff --git a/src/NPCManager.hpp b/src/NPCManager.hpp index 659a666..03b7dde 100644 --- a/src/NPCManager.hpp +++ b/src/NPCManager.hpp @@ -2,13 +2,16 @@ #define _NPCMANAGER_HPP #include "CNProtocol.hpp" +#include "PlayerManager.hpp" +#include "NPC.hpp" #include namespace NPCManager { + extern std::map NPCs; void init(); - + void updatePlayerNPCS(CNSocket* sock, PlayerView& plr); } #endif \ No newline at end of file diff --git a/src/PlayerManager.cpp b/src/PlayerManager.cpp index 021cd57..44aa96f 100644 --- a/src/PlayerManager.cpp +++ b/src/PlayerManager.cpp @@ -1,5 +1,6 @@ #include "CNProtocol.hpp" #include "PlayerManager.hpp" +#include "NPCManager.hpp" #include "CNShardServer.hpp" #include "CNShared.hpp" @@ -145,6 +146,8 @@ void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) { players[otherSock].viewable.push_back(sock); } } + + NPCManager::updatePlayerNPCS(sock, players[sock]); } void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) { diff --git a/src/PlayerManager.hpp b/src/PlayerManager.hpp index 77e8a4a..bfee3f1 100644 --- a/src/PlayerManager.hpp +++ b/src/PlayerManager.hpp @@ -11,6 +11,7 @@ struct PlayerView { std::list viewable; + std::list viewableNPCs; Player plr; int long lastHeartbeat; }; diff --git a/src/main.cpp b/src/main.cpp index 0fc3af6..4cf48d5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,7 @@ #include "PlayerManager.hpp" #include "ChatManager.hpp" #include "NanoManager.hpp" +#include "NPCManager.hpp" #include "settings.hpp" @@ -30,6 +31,7 @@ int main() { PlayerManager::init(); ChatManager::init(); NanoManager::init(); + NPCManager::init(); std::cout << "[INFO] Starting Server Threads..." << std::endl; CNLoginServer loginServer(settings::LOGINPORT); From 32a37acd5a288a953ecfc6fc76d006119e9cd048 Mon Sep 17 00:00:00 2001 From: Raymonf Date: Thu, 20 Aug 2020 17:47:27 -0400 Subject: [PATCH 06/18] Update CMakeLists to use correct binary name and pthreads if not using MinGW/VS --- CMakeLists.txt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e02ae6e..b6a8c69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,11 +17,23 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Set the OpenFusion project as the default startup project for VS set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT openfusion) +if (WIN32) + # Set the output binary name to winfusion to match the regular Makefile + set(BIN_NAME winfusion) +else() + set(BIN_NAME fusion) +endif() + include_directories(src) file(GLOB_RECURSE SOURCES src/**.cpp src/**.hpp) add_executable(openfusion ${SOURCES}) -# Set the output binary name to winfusion to match the regular Makefile -set_target_properties(openfusion PROPERTIES OUTPUT_NAME winfusion) +set_target_properties(openfusion PROPERTIES OUTPUT_NAME ${BIN_NAME}) + +# Use pthreads if not generating a VS solution or MinGW makefile (because MinGW will prefer Win32 threads) +if (NOT CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT CMAKE_GENERATOR MATCHES "MinGW Makefiles") + find_package(Threads REQUIRED) + target_link_libraries(openfusion pthread) +endif() \ No newline at end of file From c66ac111ab66e1aecf0a5774f65186c9935ed68a Mon Sep 17 00:00:00 2001 From: Raymonf Date: Thu, 20 Aug 2020 17:47:38 -0400 Subject: [PATCH 07/18] Silence codecvt deprecation warning on VC++ --- src/CNStructs.hpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/CNStructs.hpp b/src/CNStructs.hpp index 3c6bfdd..8fd70ca 100644 --- a/src/CNStructs.hpp +++ b/src/CNStructs.hpp @@ -5,14 +5,20 @@ #ifndef _CNS_HPP #define _CNS_HPP +#ifdef _MSC_VER +// codecvt_* is deprecated in C++17 and MSVC will throw an annoying warning because of that. +// Defining this before anything else to silence it. +#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING +#endif + #include #include #include -// Can't use this in MSVC. #ifndef _MSC_VER - #include +#include #else - #include +// Can't use this in MSVC. +#include #endif #include #include From 1425074ccb3b5d68f8aeb9b980e18396aef28962 Mon Sep 17 00:00:00 2001 From: CPunch Date: Thu, 20 Aug 2020 16:59:32 -0500 Subject: [PATCH 08/18] edited config.ini default back, better plr pos --- config.ini | 2 +- src/PlayerManager.cpp | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/config.ini b/config.ini index 1df6030..b6e412c 100644 --- a/config.ini +++ b/config.ini @@ -12,7 +12,7 @@ port=8002 # you'll want to change this one ip=192.168.1.183 # distance at which other players and NPCs become visible -view=1000 +view=20000 # little message players see when they enter the game motd=Welcome to OpenFusion! diff --git a/src/PlayerManager.cpp b/src/PlayerManager.cpp index 44aa96f..2d8f694 100644 --- a/src/PlayerManager.cpp +++ b/src/PlayerManager.cpp @@ -87,9 +87,9 @@ void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) { } } - std::list cachedview(players[sock].viewable); // copies the viewable - - for (CNSocket* otherSock : cachedview) { + std::list::iterator i = players[sock].viewable.begin(); + while (i != players[sock].viewable.end()) { + CNSocket* otherSock = *i; if (std::find(noView.begin(), noView.end(), otherSock) != noView.end()) { // sock shouldn't be visible, send PC_EXIT packet & remove them @@ -102,15 +102,16 @@ void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) { otherSock->sendPacket(new CNPacketData((void*)exitPacket, P_FE2CL_PC_EXIT, sizeof(sP_FE2CL_PC_EXIT), otherSock->getFEKey())); sock->sendPacket(new CNPacketData((void*)exitPacketOther, P_FE2CL_PC_EXIT, sizeof(sP_FE2CL_PC_EXIT), sock->getFEKey())); - players[sock].viewable.remove(otherSock); + players[sock].viewable.erase(i++); players[otherSock].viewable.remove(sock); + continue; } + + ++i; } - cachedview = players[sock].viewable; - for (CNSocket* otherSock : yesView) { - if (std::find(cachedview.begin(), cachedview.end(), otherSock) == cachedview.end()) { + if (std::find(players[sock].viewable.begin(), players[sock].viewable.end(), otherSock) == players[sock].viewable.end()) { // this needs to be added to the viewable players, send PC_ENTER sP_FE2CL_PC_NEW* newPlayer = (sP_FE2CL_PC_NEW*)xmalloc(sizeof(sP_FE2CL_PC_NEW)); // current connection to other player From da11220762b9ad05d15c505f0877230d75e27a18 Mon Sep 17 00:00:00 2001 From: Raymonf Date: Thu, 20 Aug 2020 18:44:30 -0400 Subject: [PATCH 09/18] Allow opening CMakeLists as a CMake project in VS Added another check just in case someone wants to do this for some reason. It's bad. You shouldn't do it. --- .gitignore | 5 +++-- CMakeLists.txt | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index ad152dc..9e87793 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -.vscode +.vscode/ bin/* notes.txt config.ini @@ -7,4 +7,5 @@ tags *~ CMakeFiles/ CMakeCache.txt -build/ \ No newline at end of file +build/ +.vs/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index b6a8c69..fc5fcda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,9 @@ add_executable(openfusion ${SOURCES}) set_target_properties(openfusion PROPERTIES OUTPUT_NAME ${BIN_NAME}) # Use pthreads if not generating a VS solution or MinGW makefile (because MinGW will prefer Win32 threads) -if (NOT CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT CMAKE_GENERATOR MATCHES "MinGW Makefiles") +# Checking if the compiler ID is MSVC will allow us to open the project as a CMake project in VS. +# It's not something you should do, but it's there if you need it... +if (NOT CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND NOT CMAKE_GENERATOR MATCHES "MinGW Makefiles") find_package(Threads REQUIRED) target_link_libraries(openfusion pthread) endif() \ No newline at end of file From 7b085e9c8bbf7e51a5f58e966c3461b0a73d76a4 Mon Sep 17 00:00:00 2001 From: CPunch Date: Thu, 20 Aug 2020 18:50:30 -0500 Subject: [PATCH 10/18] added sanity checks --- src/CNShardServer.hpp | 3 ++- src/ChatManager.cpp | 3 +++ src/NanoManager.cpp | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/CNShardServer.hpp b/src/CNShardServer.hpp index 2f69e73..c403f99 100644 --- a/src/CNShardServer.hpp +++ b/src/CNShardServer.hpp @@ -29,6 +29,7 @@ enum SHARDPACKETID { P_FE2CL_REP_NANO_ACTIVE_SUCC = 822083624, P_FE2CL_REP_PC_ENTER_SUCC = 822083586, P_FE2CL_REP_PC_LOADING_COMPLETE_SUCC = 822083833, + P_FE2CL_REP_PC_GOTO_SUCC = 822083633, P_FE2CL_REQ_LIVE_CHECK = 822083792, P_FE2CL_PC_NEW = 822083587, P_FE2CL_PC_MOVE = 822083592, @@ -42,7 +43,7 @@ enum SHARDPACKETID { P_FE2CL_PC_SLOPE = 822083705, P_FE2CL_NPC_ENTER = 822083595, P_FE2CL_NPC_EXIT = 822083596, - P_FE2CL_REP_PC_GOTO_SUCC = 822083633, + P_FE2CL_ANNOUNCE_MSG = 822083778, P_FE2CL_GM_REP_PC_SET_VALUE = 822083781, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC = 822083602, P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT = 822083730, diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index 451bd15..efbc77f 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -9,6 +9,9 @@ void ChatManager::init() { } void ChatManager::chatHandler(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE)) + return; // malformed packet + sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE* chat = (sP_CL2FE_REQ_SEND_FREECHAT_MESSAGE*)data->buf; PlayerView plr = PlayerManager::players[sock]; diff --git a/src/NanoManager.cpp b/src/NanoManager.cpp index 4f7e5f8..5d2a560 100644 --- a/src/NanoManager.cpp +++ b/src/NanoManager.cpp @@ -8,6 +8,9 @@ void NanoManager::init() { } void NanoManager::nanoSummonHandler(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_REQ_NANO_ACTIVE)) + return; // malformed packet + sP_CL2FE_REQ_NANO_ACTIVE* nano = (sP_CL2FE_REQ_NANO_ACTIVE*)data->buf; PlayerView plr = PlayerManager::players[sock]; From e044b4251a7a2d7074d4b5abee4c6d559affc85b Mon Sep 17 00:00:00 2001 From: dongresource <69976329+dongresource@users.noreply.github.com> Date: Fri, 21 Aug 2020 02:37:34 +0200 Subject: [PATCH 11/18] Cleanup indentation. (#10) --- src/CNShardServer.hpp | 2 +- src/CNStructs.hpp | 4 ++-- src/NanoManager.cpp | 20 ++++++++++---------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/CNShardServer.hpp b/src/CNShardServer.hpp index c403f99..139f71e 100644 --- a/src/CNShardServer.hpp +++ b/src/CNShardServer.hpp @@ -45,7 +45,7 @@ enum SHARDPACKETID { P_FE2CL_NPC_EXIT = 822083596, P_FE2CL_ANNOUNCE_MSG = 822083778, P_FE2CL_GM_REP_PC_SET_VALUE = 822083781, - P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC = 822083602, + P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC = 822083602, P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT = 822083730, P_FE2CL_REP_PC_EXIT_SUCC = 822083589, P_FE2CL_PC_MOTD_LOGIN = 822083793 diff --git a/src/CNStructs.hpp b/src/CNStructs.hpp index 8fd70ca..4007758 100644 --- a/src/CNStructs.hpp +++ b/src/CNStructs.hpp @@ -35,9 +35,9 @@ uint64_t getTime(); #define CNPROTO_VERSION_0104 #if defined(CNPROTO_VERSION_0104) - #include "structs/0104.hpp" + #include "structs/0104.hpp" #elif defined(CNPROTO_VERSION_0728) - #include "structs/0728.hpp" + #include "structs/0728.hpp" #endif #endif diff --git a/src/NanoManager.cpp b/src/NanoManager.cpp index 5d2a560..4e773d0 100644 --- a/src/NanoManager.cpp +++ b/src/NanoManager.cpp @@ -4,20 +4,20 @@ #include "PlayerManager.hpp" void NanoManager::init() { - REGISTER_SHARD_PACKET(P_CL2FE_REQ_NANO_ACTIVE, nanoSummonHandler); + REGISTER_SHARD_PACKET(P_CL2FE_REQ_NANO_ACTIVE, nanoSummonHandler); } void NanoManager::nanoSummonHandler(CNSocket* sock, CNPacketData* data) { - if (data->size != sizeof(sP_CL2FE_REQ_NANO_ACTIVE)) + if (data->size != sizeof(sP_CL2FE_REQ_NANO_ACTIVE)) return; // malformed packet - sP_CL2FE_REQ_NANO_ACTIVE* nano = (sP_CL2FE_REQ_NANO_ACTIVE*)data->buf; - PlayerView plr = PlayerManager::players[sock]; + sP_CL2FE_REQ_NANO_ACTIVE* nano = (sP_CL2FE_REQ_NANO_ACTIVE*)data->buf; + PlayerView plr = PlayerManager::players[sock]; - // Send to client - sP_FE2CL_REP_NANO_ACTIVE_SUCC* resp = (sP_FE2CL_REP_NANO_ACTIVE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_NANO_ACTIVE_SUCC)); - resp->iActiveNanoSlotNum = nano->iNanoSlotNum; - sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_NANO_ACTIVE_SUCC, sizeof(sP_FE2CL_REP_NANO_ACTIVE_SUCC), sock->getFEKey())); + // Send to client + sP_FE2CL_REP_NANO_ACTIVE_SUCC* resp = (sP_FE2CL_REP_NANO_ACTIVE_SUCC*)xmalloc(sizeof(sP_FE2CL_REP_NANO_ACTIVE_SUCC)); + resp->iActiveNanoSlotNum = nano->iNanoSlotNum; + sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_NANO_ACTIVE_SUCC, sizeof(sP_FE2CL_REP_NANO_ACTIVE_SUCC), sock->getFEKey())); - std::cout << U16toU8(plr.plr.PCStyle.szFirstName) << U16toU8(plr.plr.PCStyle.szLastName) << " requested to summon nano slot: " << nano->iNanoSlotNum << std::endl; -} \ No newline at end of file + std::cout << U16toU8(plr.plr.PCStyle.szFirstName) << U16toU8(plr.plr.PCStyle.szLastName) << " requested to summon nano slot: " << nano->iNanoSlotNum << std::endl; +} From aa2adcd9e2a16cc1c1199e2495bcbc1724cef048 Mon Sep 17 00:00:00 2001 From: JadeShrineMaiden <69916714+JadeShrineMaiden@users.noreply.github.com> Date: Fri, 21 Aug 2020 03:10:14 +0100 Subject: [PATCH 12/18] Items Implementation (#11) * Item Manager (Initial Implementation) * Item Manager (Second Phase) * Item Manager (Phase Three) * Not Working Code * Inventory Implementation (Complete?) * Items Implementation -Fixed Indentations -Final touches to make it all work * Update Makefile * Added small comments -- needs to be fixed --- Makefile | 2 ++ src/CNLoginServer.cpp | 9 ++++++- src/CNShardServer.hpp | 3 +++ src/ItemManager.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++ src/ItemManager.hpp | 11 ++++++++ src/Player.hpp | 1 + src/main.cpp | 2 ++ src/structs/0104.hpp | 1 + 8 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/ItemManager.cpp create mode 100644 src/ItemManager.hpp diff --git a/Makefile b/Makefile index ee6e209..8f455c9 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,7 @@ SRC=\ src/CNStructs.cpp\ src/main.cpp\ src/NanoManager.cpp\ + src/ItemManager.cpp\ src/NPCManager.cpp\ src/Player.cpp\ src/PlayerManager.cpp\ @@ -36,6 +37,7 @@ HDR=\ src/CNStructs.hpp\ src/INIReader.hpp\ src/NanoManager.hpp\ + src/ItemManager.hpp\ src/NPCManager.hpp\ src/Player.hpp\ src/PlayerManager.hpp\ diff --git a/src/CNLoginServer.cpp b/src/CNLoginServer.cpp index 6017a0f..cc3cc4c 100644 --- a/src/CNLoginServer.cpp +++ b/src/CNLoginServer.cpp @@ -93,13 +93,20 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) { loginSessions[sock].characters[UID].PCStyle2 = charInfo->sPC_Style2; for (int i = 0; i < AEQUIP_COUNT; i++) { - // setup item + // setup equips charInfo->aEquip[i].iID = 0; charInfo->aEquip[i].iType = i; charInfo->aEquip[i].iOpt = 0; loginSessions[sock].characters[UID].Equip[i] = charInfo->aEquip[i]; } + for (int i = 0; i < AINVEN_COUNT; i++) { + // setup inventories + loginSessions[sock].characters[UID].Inven[i].iID = 0; + loginSessions[sock].characters[UID].Inven[i].iType = 0; + loginSessions[sock].characters[UID].Inven[i].iOpt = 0; + } + // set default to the first character if (i == 0) loginSessions[sock].selectedChar = UID; diff --git a/src/CNShardServer.hpp b/src/CNShardServer.hpp index 139f71e..751c03d 100644 --- a/src/CNShardServer.hpp +++ b/src/CNShardServer.hpp @@ -23,6 +23,7 @@ enum SHARDPACKETID { P_CL2FE_GM_REQ_PC_SET_VALUE = 318767211, P_CL2FE_REQ_SEND_FREECHAT_MESSAGE = 318767111, P_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT = 318767184, + P_CL2FE_REQ_ITEM_MOVE = 318767114, P_CL2FE_REQ_PC_EXIT = 318767106, // shard 2 client @@ -47,6 +48,8 @@ enum SHARDPACKETID { P_FE2CL_GM_REP_PC_SET_VALUE = 822083781, P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC = 822083602, P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT = 822083730, + P_FE2CL_PC_ITEM_MOVE_SUCC = 822083610, + P_FE2CL_PC_EQUIP_CHANGE = 822083611, P_FE2CL_REP_PC_EXIT_SUCC = 822083589, P_FE2CL_PC_MOTD_LOGIN = 822083793 }; diff --git a/src/ItemManager.cpp b/src/ItemManager.cpp new file mode 100644 index 0000000..7937e69 --- /dev/null +++ b/src/ItemManager.cpp @@ -0,0 +1,63 @@ +#include "CNShardServer.hpp" +#include "CNStructs.hpp" +#include "ItemManager.hpp" +#include "PlayerManager.hpp" +#include "Player.hpp" + +void ItemManager::init() { + REGISTER_SHARD_PACKET(P_CL2FE_REQ_ITEM_MOVE, itemMoveHandler); + REGISTER_SHARD_PACKET(P_FE2CL_PC_EQUIP_CHANGE, itemMoveHandler); +} + +void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_REQ_ITEM_MOVE)) + return; // ignore the malformed packet + + sP_CL2FE_REQ_ITEM_MOVE* itemmove = (sP_CL2FE_REQ_ITEM_MOVE*)data->buf; + sP_FE2CL_PC_ITEM_MOVE_SUCC* resp = (sP_FE2CL_PC_ITEM_MOVE_SUCC*)xmalloc(sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC)); + + PlayerView plr = PlayerManager::players[sock]; + + //weird flip flop but it makes things happen + resp->eFrom = itemmove->eTo; + resp->iFromSlotNum = itemmove->iToSlotNum; + resp->eTo = itemmove->eFrom; + resp->iToSlotNum = itemmove->iFromSlotNum; + + //eFrom 0 means from equip, 1 means from inventory + if (itemmove->eFrom == 0) { + resp->FromSlotItem = plr.plr.Equip[itemmove->iFromSlotNum]; + } else { + resp->FromSlotItem = plr.plr.Inven[itemmove->iFromSlotNum]; + } + + //eTo 0 means to equip, 1 means to inventory + if (itemmove->eTo == 0) { + resp->ToSlotItem = plr.plr.Equip[itemmove->iToSlotNum]; + plr.plr.Equip[itemmove->iToSlotNum] = resp->FromSlotItem; + } else { + resp->ToSlotItem = plr.plr.Inven[itemmove->iToSlotNum]; + plr.plr.Inven[itemmove->iToSlotNum] = resp->FromSlotItem; + } + + if (itemmove->eFrom == 0) { + plr.plr.Equip[itemmove->iFromSlotNum] = resp->ToSlotItem; + + sP_FE2CL_PC_EQUIP_CHANGE* resp2 = (sP_FE2CL_PC_EQUIP_CHANGE*)xmalloc(sizeof(sP_FE2CL_PC_EQUIP_CHANGE)); + + resp2->iPC_ID = plr.plr.iID; + resp2->iEquipSlotNum = resp->iToSlotNum; + resp2->EquipSlotItem = resp->ToSlotItem; + + for (CNSocket* otherSock : plr.viewable) { + otherSock->sendPacket(new CNPacketData((void*)resp2, P_FE2CL_PC_EQUIP_CHANGE, sizeof(sP_FE2CL_PC_EQUIP_CHANGE), otherSock->getFEKey())); + } + + } else { + plr.plr.Inven[itemmove->iFromSlotNum] = resp->ToSlotItem; + } + + PlayerManager::players[sock] = plr; + + sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_PC_ITEM_MOVE_SUCC, sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC), sock->getFEKey())); +} \ No newline at end of file diff --git a/src/ItemManager.hpp b/src/ItemManager.hpp new file mode 100644 index 0000000..0036907 --- /dev/null +++ b/src/ItemManager.hpp @@ -0,0 +1,11 @@ +#ifndef _IM_HPP +#define _IM_HPP + +#include "CNShardServer.hpp" + +namespace ItemManager { + void init(); + void itemMoveHandler(CNSocket* sock, CNPacketData* data); +} + +#endif \ No newline at end of file diff --git a/src/Player.hpp b/src/Player.hpp index 2f2d8d2..991a842 100644 --- a/src/Player.hpp +++ b/src/Player.hpp @@ -20,6 +20,7 @@ struct Player { int x, y, z, angle; sItemBase Equip[AEQUIP_COUNT]; + sItemBase Inven[AINVEN_COUNT]; }; #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 4cf48d5..56e9055 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include "CNShardServer.hpp" #include "PlayerManager.hpp" #include "ChatManager.hpp" +#include "ItemManager.hpp" #include "NanoManager.hpp" #include "NPCManager.hpp" @@ -30,6 +31,7 @@ int main() { std::cout << "[INFO] Intializing Packet Managers..." << std::endl; PlayerManager::init(); ChatManager::init(); + ItemManager::init(); NanoManager::init(); NPCManager::init(); diff --git a/src/structs/0104.hpp b/src/structs/0104.hpp index e238410..bd70161 100644 --- a/src/structs/0104.hpp +++ b/src/structs/0104.hpp @@ -1,6 +1,7 @@ /* genstructs.py */ #define AEQUIP_COUNT 9 +#define AINVEN_COUNT 50 #pragma pack(push) From faf73fc835930e60cb9d6c28972f2e7ce9058e0a Mon Sep 17 00:00:00 2001 From: Raymonf Date: Thu, 20 Aug 2020 22:46:48 -0400 Subject: [PATCH 13/18] Initial AppVeyor build configuration (#12) --- appveyor.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..e681892 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,37 @@ +version: 'openfusion-{branch}-{build}' + +image: + - Visual Studio 2019 + - Ubuntu2004 + +platform: + - x64 + +configuration: + - Release + +for: +- + matrix: + only: + - image: Ubuntu2004 + before_build: + - mkdir -p bin + build_script: + - make + artifacts: + - path: bin + name: ubuntu20_04-bin-x64 + type: zip +- + matrix: + only: + - image: Visual Studio 2019 + before_build: + - cmake -B build + build_script: + - msbuild build/OpenFusion.sln /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" + artifacts: + - path: bin + name: windows-vs2019-bin-x64 + type: zip From b89df8d49772d93f647ef1bd1c7bf860a50cc8d6 Mon Sep 17 00:00:00 2001 From: Raymonf Date: Thu, 20 Aug 2020 22:54:11 -0400 Subject: [PATCH 14/18] Mention AppVeyor in the readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 0c7610d..60f0e3d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ ![](res/radiorave_logo.png) +[![AppVeyor](https://ci.appveyor.com/api/projects/status/github/OpenFusionProject/OpenFusion?svg=true)](https://ci.appveyor.com/project/Raymonf/openfusion) + OpenFusion is a landwalker server for FusionFall. It currently supports versions `beta-20100104` and `beta-20100728` of the original game. Further documentation pending. @@ -21,6 +23,8 @@ Currently the client by default connects to a public server hosted by Cake. Chan You have two randomized characters available to you on the Character Selection screen, one boy, one girl. You can also make your own character and play through the tutorial. The tutorial can be skipped by pressing the ~ key. +If you want, [compiled binaries (artifacts) for each new commit can be found on AppVeyor.](https://ci.appveyor.com/project/Raymonf/openfusion) + For a more detailed overview of the game's architecture and how to configure it, read the following sections. ## Architecture From e3d53e8dcf9de07af2c4c0c81396910ec757feca Mon Sep 17 00:00:00 2001 From: CakeLancelot Date: Thu, 20 Aug 2020 22:04:35 -0500 Subject: [PATCH 15/18] Add Discord badge to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 60f0e3d..a242792 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ ![](res/radiorave_logo.png) [![AppVeyor](https://ci.appveyor.com/api/projects/status/github/OpenFusionProject/OpenFusion?svg=true)](https://ci.appveyor.com/project/Raymonf/openfusion) +[![Discord](https://img.shields.io/badge/chat-on%20discord-7289da.svg?logo=discord)](https://discord.gg/DYavckB) OpenFusion is a landwalker server for FusionFall. It currently supports versions `beta-20100104` and `beta-20100728` of the original game. From eee1b52722d4e457079c5b88073d7516ed8096e4 Mon Sep 17 00:00:00 2001 From: CPunch Date: Thu, 20 Aug 2020 22:25:39 -0500 Subject: [PATCH 16/18] fixed ItemManager --- src/ItemManager.cpp | 73 ++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/src/ItemManager.cpp b/src/ItemManager.cpp index 7937e69..b635a7e 100644 --- a/src/ItemManager.cpp +++ b/src/ItemManager.cpp @@ -12,52 +12,65 @@ void ItemManager::init() { void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_ITEM_MOVE)) return; // ignore the malformed packet - + sP_CL2FE_REQ_ITEM_MOVE* itemmove = (sP_CL2FE_REQ_ITEM_MOVE*)data->buf; sP_FE2CL_PC_ITEM_MOVE_SUCC* resp = (sP_FE2CL_PC_ITEM_MOVE_SUCC*)xmalloc(sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC)); - + PlayerView plr = PlayerManager::players[sock]; - - //weird flip flop but it makes things happen - resp->eFrom = itemmove->eTo; - resp->iFromSlotNum = itemmove->iToSlotNum; - resp->eTo = itemmove->eFrom; - resp->iToSlotNum = itemmove->iFromSlotNum; + sItemBase fromItem; + sItemBase toItem; - //eFrom 0 means from equip, 1 means from inventory + // eFrom 0 means from equip if (itemmove->eFrom == 0) { - resp->FromSlotItem = plr.plr.Equip[itemmove->iFromSlotNum]; + // unequiping an item + std::cout << "unequipting item" << std::endl; + fromItem = plr.plr.Equip[itemmove->iFromSlotNum]; } else { - resp->FromSlotItem = plr.plr.Inven[itemmove->iFromSlotNum]; + fromItem = plr.plr.Inven[itemmove->iFromSlotNum]; } - //eTo 0 means to equip, 1 means to inventory + // eTo 0 means to equip if (itemmove->eTo == 0) { - resp->ToSlotItem = plr.plr.Equip[itemmove->iToSlotNum]; - plr.plr.Equip[itemmove->iToSlotNum] = resp->FromSlotItem; + std::cout << "equipting item" << std::endl; + // equiping an item + toItem = plr.plr.Equip[itemmove->iToSlotNum]; + plr.plr.Equip[itemmove->iToSlotNum] = fromItem; } else { - resp->ToSlotItem = plr.plr.Inven[itemmove->iToSlotNum]; - plr.plr.Inven[itemmove->iToSlotNum] = resp->FromSlotItem; + toItem = plr.plr.Inven[itemmove->iToSlotNum]; + plr.plr.Inven[itemmove->iToSlotNum] = fromItem; } - + if (itemmove->eFrom == 0) { - plr.plr.Equip[itemmove->iFromSlotNum] = resp->ToSlotItem; - - sP_FE2CL_PC_EQUIP_CHANGE* resp2 = (sP_FE2CL_PC_EQUIP_CHANGE*)xmalloc(sizeof(sP_FE2CL_PC_EQUIP_CHANGE)); - - resp2->iPC_ID = plr.plr.iID; - resp2->iEquipSlotNum = resp->iToSlotNum; - resp2->EquipSlotItem = resp->ToSlotItem; - - for (CNSocket* otherSock : plr.viewable) { - otherSock->sendPacket(new CNPacketData((void*)resp2, P_FE2CL_PC_EQUIP_CHANGE, sizeof(sP_FE2CL_PC_EQUIP_CHANGE), otherSock->getFEKey())); - } - + plr.plr.Equip[itemmove->iFromSlotNum] = toItem; } else { - plr.plr.Inven[itemmove->iFromSlotNum] = resp->ToSlotItem; + plr.plr.Inven[itemmove->iFromSlotNum] = toItem; } + if (itemmove->eFrom == 0 || itemmove->eTo == 0) { + for (CNSocket* otherSock : plr.viewable) { + sP_FE2CL_PC_EQUIP_CHANGE* resp2 = (sP_FE2CL_PC_EQUIP_CHANGE*)xmalloc(sizeof(sP_FE2CL_PC_EQUIP_CHANGE)); + + resp2->iPC_ID = plr.plr.iID; + if (itemmove->eFrom == 0) { + resp2->iEquipSlotNum = itemmove->iFromSlotNum; + resp2->EquipSlotItem = toItem; + } + else { + resp2->iEquipSlotNum = itemmove->iToSlotNum; + resp2->EquipSlotItem = fromItem; + } + otherSock->sendPacket(new CNPacketData((void*)resp2, P_FE2CL_PC_EQUIP_CHANGE, sizeof(sP_FE2CL_PC_EQUIP_CHANGE), otherSock->getFEKey())); + } + } + PlayerManager::players[sock] = plr; + resp->eTo = itemmove->eFrom; + resp->iToSlotNum = itemmove->iFromSlotNum; + resp->ToSlotItem = toItem; + resp->eFrom = itemmove->eTo; + resp->iFromSlotNum = itemmove->iToSlotNum; + resp->FromSlotItem = fromItem; + sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_PC_ITEM_MOVE_SUCC, sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC), sock->getFEKey())); } \ No newline at end of file From 0041da795a3e3d45b8d6971a6caa73a8d687fdbe Mon Sep 17 00:00:00 2001 From: Raymonf Date: Fri, 21 Aug 2020 01:18:19 -0400 Subject: [PATCH 17/18] Build multiple packet versions on AppVeyor for Windows (#14) * Move to PowerShell script for Windows build * Allow CMake to override struct version * PACKET_VERSION option * Rename CNPROTO_CUSTOM to CNPROTO_OVERRIDE Co-authored-by: Raymonf --- CMakeLists.txt | 9 ++++++++- appveyor.yml | 38 +++++++++++++++++++++++++++++++++----- src/CNStructs.hpp | 19 ++++++++++++------- 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc5fcda..dada585 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,13 @@ project(OpenFusion) set(CMAKE_CXX_STANDARD 17) +# OpenFusion supports multiple packet/struct versions +# 0104 is the default version to build which can be changed +# For example: cmake -B build -DPACKET_VERSION=0728 +OPTION(PACKET_VERSION "The packet version to build" "0104") + +ADD_DEFINITIONS(-DCNPROTO_OVERRIDE -DCNPROTO_VERSION_${PACKET_VERSION}) + # Disallow in-source builds if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) message(FATAL_ERROR "In-source builds not allowed. Please refer to the wiki for more information. Please remove the CMakeFiles folder and the CMakeCache.txt file.") @@ -38,4 +45,4 @@ set_target_properties(openfusion PROPERTIES OUTPUT_NAME ${BIN_NAME}) if (NOT CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND NOT CMAKE_GENERATOR MATCHES "MinGW Makefiles") find_package(Threads REQUIRED) target_link_libraries(openfusion pthread) -endif() \ No newline at end of file +endif() diff --git a/appveyor.yml b/appveyor.yml index e681892..acad59a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -25,12 +25,40 @@ for: type: zip - matrix: - only: - - image: Visual Studio 2019 - before_build: - - cmake -B build + only: + - image: Visual Studio 2019 build_script: - - msbuild build/OpenFusion.sln /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" + - ps: | + $versions = "0104", "0728" + $configurations = "Release", "Debug" + + # AppVeyor uses VS2019 Community + $vsPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community" + + Import-Module "$vsPath\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" + Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation + + foreach ($version in $versions) { + if (Test-Path -LiteralPath "build") { + Remove-Item "build" -Recurse + Write-Output "Deleted existing build folder" + } + Invoke-Expression "cmake -B build -DPACKET_VERSION=$version" + if ($LASTEXITCODE -ne "0") { + Write-Error "cmake generation failed for version $version" -ErrorAction Stop + } + Write-Output "Generated build files for version $version" + + foreach ($configuration in $configurations) { + Write-Output "Building version $version $configuration" + Invoke-Expression "msbuild build\OpenFusion.sln /p:Configuration=$configuration" + if ($LASTEXITCODE -ne "0") { + Write-Error "msbuild build failed for version $version" -ErrorAction Stop + } + Rename-Item -Path "bin/$configuration" -newName "$version-$configuration" + Write-Output "Built version $version $configuration" + } + } artifacts: - path: bin name: windows-vs2019-bin-x64 diff --git a/src/CNStructs.hpp b/src/CNStructs.hpp index 4007758..9df5f31 100644 --- a/src/CNStructs.hpp +++ b/src/CNStructs.hpp @@ -6,19 +6,19 @@ #define _CNS_HPP #ifdef _MSC_VER -// codecvt_* is deprecated in C++17 and MSVC will throw an annoying warning because of that. -// Defining this before anything else to silence it. -#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING + // codecvt_* is deprecated in C++17 and MSVC will throw an annoying warning because of that. + // Defining this before anything else to silence it. + #define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING #endif #include #include #include #ifndef _MSC_VER -#include + #include #else // Can't use this in MSVC. -#include + #include #endif #include #include @@ -31,8 +31,13 @@ std::string U16toU8(char16_t* src); int U8toU16(std::string src, char16_t* des); // returns number of char16_t that was written at des uint64_t getTime(); -//#define CNPROTO_VERSION_0728 -#define CNPROTO_VERSION_0104 +// The CNPROTO_OVERRIDE definition is defined by cmake if you use it. +// If you don't use cmake, feel free to comment this out and change it around. +// Otherwise, use the PACKET_VERSION option (e.g. -DPACKET_VERSION=0104 in the cmake command) to change it. +#if !defined(CNPROTO_OVERRIDE) + //#define CNPROTO_VERSION_0728 + #define CNPROTO_VERSION_0104 +#endif #if defined(CNPROTO_VERSION_0104) #include "structs/0104.hpp" From 5d0b30b4cb470b74491ba121e6218816eb77e35f Mon Sep 17 00:00:00 2001 From: CPunch Date: Fri, 21 Aug 2020 00:31:00 -0500 Subject: [PATCH 18/18] added AINVEN_COUT for 0728 --- src/structs/0728.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/structs/0728.hpp b/src/structs/0728.hpp index 036c23b..27bbd47 100644 --- a/src/structs/0728.hpp +++ b/src/structs/0728.hpp @@ -1,6 +1,7 @@ /* genstructs.py */ #define AEQUIP_COUNT 12 +#define AINVEN_COUNT 50 #pragma pack(push)