diff --git a/xpcPlugin/DataManager.cpp b/xpcPlugin/DataManager.cpp index 54932a7..86d3d80 100644 --- a/xpcPlugin/DataManager.cpp +++ b/xpcPlugin/DataManager.cpp @@ -176,7 +176,7 @@ namespace XPC } } - std::size_t DataManager::Get(std::string dref, float values[], std::size_t size) + int DataManager::Get(std::string dref, float values[], int size) { XPLMDataRef& xdref = sdrefs[dref]; if (xdref == nullptr) @@ -200,7 +200,7 @@ namespace XPC { case 1: // Integer { - values[0] = XPLMGetDatai(xdref); + values[0] = (float)XPLMGetDatai(xdref); #if LOG_VERBOSITY > 4 Log::FormatLine(" value was %i", (int)values[0]); #endif @@ -208,7 +208,7 @@ namespace XPC } case 4: // Double { - values[0] = XPLMGetDatad(xdref); + values[0] = (float)XPLMGetDatad(xdref); #if LOG_VERBOSITY > 4 Log::FormatLine(" value was %f", values[0]); #endif @@ -233,7 +233,7 @@ namespace XPC XPLMGetDatavi(xdref, iValues, 0, drefSize); for (int i = 0; i < drefSize; ++i) { - values[i] = iValues[i]; + values[i] = (float)iValues[i]; } #if LOG_VERBOSITY > 4 Log::FormatLine(" value count was %i", drefSize); @@ -281,7 +281,7 @@ namespace XPC return value; } - std::size_t DataManager::GetFloatArray(DREF dref, float values[], std::size_t size, std::uint8_t aircraft) + int DataManager::GetFloatArray(DREF dref, float values[], int size, std::uint8_t aircraft) { const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref]; int resultSize = XPLMGetDatavf(xdref, values, 0, size); @@ -291,7 +291,7 @@ namespace XPC return resultSize; } - std::size_t DataManager::GetIntArray(DREF dref, int values[], std::size_t size, std::uint8_t aircraft) + int DataManager::GetIntArray(DREF dref, int values[], int size, std::uint8_t aircraft) { const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref]; int resultSize = XPLMGetDatavi(xdref, values, 0, size); @@ -328,29 +328,29 @@ namespace XPC XPLMSetDatai(xdref, value); } - void DataManager::Set(DREF dref, float values[], std::size_t size, std::uint8_t aircraft) + void DataManager::Set(DREF dref, float values[], int size, std::uint8_t aircraft) { const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref]; #if LOG_VERBOSITY > 4 Log::FormatLine("[DMAN] Set DREF %i (x:%X) (%i values) for a/c %i", dref, xdref, size, aircraft); #endif - std::size_t drefSize = XPLMGetDatavf(xdref, NULL, 0, 0); + int drefSize = XPLMGetDatavf(xdref, NULL, 0, 0); drefSize = min(drefSize, size); XPLMSetDatavf(xdref, values, 0, drefSize); } - void DataManager::Set(DREF dref, int values[], std::size_t size, std::uint8_t aircraft) + void DataManager::Set(DREF dref, int values[], int size, std::uint8_t aircraft) { const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref]; #if LOG_VERBOSITY > 4 Log::FormatLine("[DMAN] Setting DREF %i (x:%X) (%i values) for a/c %i", dref, xdref, size, aircraft); #endif - std::size_t drefSize = XPLMGetDatavi(xdref, NULL, 0, 0); + int drefSize = XPLMGetDatavi(xdref, NULL, 0, 0); drefSize = min(drefSize, size); XPLMSetDatavi(xdref, values, 0, drefSize); } - void DataManager::Set(std::string dref, float values[], std::size_t size) + void DataManager::Set(std::string dref, float values[], int size) { XPLMDataRef& xdref = sdrefs[dref]; if (xdref == nullptr) diff --git a/xpcPlugin/DataManager.h b/xpcPlugin/DataManager.h index d153da9..85eb018 100644 --- a/xpcPlugin/DataManager.h +++ b/xpcPlugin/DataManager.h @@ -170,7 +170,7 @@ namespace XPC /// doubles where high precision is required, using this method may result /// in a loss of precision. In that case, consider using one of the /// strongly typed methods instead. - static std::size_t Get(std::string dref, float values[], std::size_t size); + static int Get(std::string dref, float values[], int size); /// Gets the value of a double dataref. /// @@ -248,7 +248,7 @@ namespace XPC /// method, most drefs are not valid for multiplayer aircraft. All drefs /// that are not prefixed with 'MP' are valid for the player aircraft. /// 'MP' drefs should be called with aircraft 0. - static std::size_t GetFloatArray(DREF dref, float values[], std::size_t size, std::uint8_t aircraft = 0); + static int GetFloatArray(DREF dref, float values[], int size, std::uint8_t aircraft = 0); /// Gets the value of an int array dataref. @@ -270,7 +270,7 @@ namespace XPC /// method, most drefs are not valid for multiplayer aircraft. All drefs /// that are not prefixed with 'MP' are valid for the player aircraft. /// 'MP' drefs should be called with aircraft 0. - static std::size_t GetIntArray(DREF dref, int values[], std::size_t size, std::uint8_t aircraft = 0); + static int GetIntArray(DREF dref, int values[], int size, std::uint8_t aircraft = 0); /// Sets the value of a dataref /// @@ -290,7 +290,7 @@ namespace XPC /// doubles where high precision is required, using this method may result /// in a loss of precision. In that case, consider using one of the /// strongly typed methods instead. - static void Set(std::string dref, float values[], std::size_t size); + static void Set(std::string dref, float values[], int size); /// Sets the value of a double dataref. /// @@ -359,7 +359,7 @@ namespace XPC /// method, most drefs are not valid for multiplayer aircraft. All drefs /// that are not prefixed with 'MP' are valid for the player aircraft. /// 'MP' drefs should be called with aircraft 0. - static void Set(DREF dref, float values[], std::size_t size, std::uint8_t aircraft = 0); + static void Set(DREF dref, float values[], int size, std::uint8_t aircraft = 0); /// Sets the value of an integer array dataref. /// @@ -377,7 +377,7 @@ namespace XPC /// method, most drefs are not valid for multiplayer aircraft. All drefs /// that are not prefixed with 'MP' are valid for the player aircraft. /// 'MP' drefs should be called with aircraft 0. - static void Set(DREF dref, int values[], std::size_t size, std::uint8_t aircraft = 0); + static void Set(DREF dref, int values[], int size, std::uint8_t aircraft = 0); /// Sets the landing gear for the specified airplane. /// diff --git a/xpcPlugin/Drawing.cpp b/xpcPlugin/Drawing.cpp index 2dd93a8..6cb3ff6 100644 --- a/xpcPlugin/Drawing.cpp +++ b/xpcPlugin/Drawing.cpp @@ -15,12 +15,13 @@ // without specific prior written permission from the authors or // Laminar Research, respectively. #include "Drawing.h" + #include "XPLMDisplay.h" #include "XPLMGraphics.h" #include "XPLMDataAccess.h" -#include -#include -#include + +#include +#include //OpenGL includes #if IBM #include @@ -65,13 +66,23 @@ namespace XPC //Internal Functions static int cmp(const void * a, const void * b) { - return (*(size_t*)a - *(size_t*)b); + std::size_t sa = *(size_t*)a; + std::size_t sb = *(size_t*)b; + if (sa > sb) + { + return 1; + } + if (sb > sa) + { + return -1; + } + return 0; } static void gl_drawCube(float x, float y, float z, float d) { //tan(0.25) degrees. Should scale all markers to appear about the same size - const float TAN = 0.00436335082070156648652885284203; + const float TAN = 0.00436335F; float h = d * TAN; glBegin(GL_QUAD_STRIP); diff --git a/xpcPlugin/Drawing.h b/xpcPlugin/Drawing.h index 7dd2927..dbc57e4 100644 --- a/xpcPlugin/Drawing.h +++ b/xpcPlugin/Drawing.h @@ -3,9 +3,10 @@ #ifndef XPC_DRAWING_H #define XPC_DRAWING_H -#include #include "xplaneConnect.h" +#include + namespace XPC { /// Handles tasks that involve drawing to the screen in X-Plane. diff --git a/xpcPlugin/MessageHandlers.cpp b/xpcPlugin/MessageHandlers.cpp index 1d93cec..ac8c35a 100644 --- a/xpcPlugin/MessageHandlers.cpp +++ b/xpcPlugin/MessageHandlers.cpp @@ -205,7 +205,7 @@ namespace XPC float thr = *((float*)(buffer + 17)); std::int8_t gear = buffer[21]; float flaps = *((float*)(buffer + 22)); - float aircraft = 0; + std::uint8_t aircraft = 0; if (size == 27) { aircraft = buffer[26]; @@ -241,7 +241,27 @@ namespace XPC // Parse data const std::uint8_t* buffer = msg.GetBuffer(); std::size_t size = msg.GetSize(); - std::uint8_t numCols = (size - 5) / 36; + std::size_t numCols = (size - 5) / 36; + if (numCols > 0) + { +#if LOG_VERBOSITY > 3 + Log::FormatLine("[DATA] Message Received (Conn %i)", connection.id); +#endif + } + if (numCols > 32) // Error. Will overflow values + { +#if LOG_VERBOSITY > 2 + Log::FormatLine("[DATA] ERROR numCols to large."); +#endif + return; + } + else + { +#if LOG_VERBOSITY > 2 + Log::FormatLine("[DATA] WARNING: Empty data packet received (Conn %i)", connection.id); +#endif + return; + } float values[32][9]; for (int i = 0; i < numCols; ++i) { @@ -250,19 +270,6 @@ namespace XPC } // Update log -#if LOG_VERBOSITY > 1 - if (numCols > 0) - { - // UPDATE LOG - Log::FormatLine("[DATA] Message Received (Conn %i)", connection.id); - } - else - { - // UPDATE LOG - Log::FormatLine("[DATA] WARNING: Empty data packet received (Conn %i)", connection.id); - return; - } -#endif float savedAlpha = -998; float savedHPath = -998; @@ -449,7 +456,7 @@ namespace XPC for (int i = 0; i < drefCount; ++i) { float values[255]; - std::size_t count = DataManager::Get(connection.getdRequest[i], values, 255); + int count = DataManager::Get(connection.getdRequest[i], values, 255); response[cur++] = count; memcpy(response + cur, values, count * sizeof(float)); cur += count * sizeof(float); diff --git a/xpcPlugin/UDPSocket.cpp b/xpcPlugin/UDPSocket.cpp index b8ece7a..9795205 100644 --- a/xpcPlugin/UDPSocket.cpp +++ b/xpcPlugin/UDPSocket.cpp @@ -141,7 +141,8 @@ namespace XPC { remoteHost = "127.0.0.1"; } - std::uint32_t ip = inet_addr(remoteHost.c_str()); + std::uint32_t ip; + inet_pton(AF_INET, remoteHost.c_str(), &ip); SendTo(buffer, len, ip, remotePort); } @@ -160,7 +161,7 @@ namespace XPC setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)); buffer[4] = (std::uint8_t)len; - if (sendto(sock, (char*)buffer, len, 0, (const struct sockaddr *) &remoteAddr, sizeof(remoteAddr)) < 0) + if (sendto(sock, (char*)buffer, (int)len, 0, (const struct sockaddr *) &remoteAddr, sizeof(remoteAddr)) < 0) { #if LOG_VERBOSITY > 0 Log::FormatLine("[SOCK] Send failed. (remote: %s:%d)", remoteAddr, remotePort); diff --git a/xpcPlugin/XPlaneConnect/64/win.xpl b/xpcPlugin/XPlaneConnect/64/win.xpl index 19295f1..3438995 100644 Binary files a/xpcPlugin/XPlaneConnect/64/win.xpl and b/xpcPlugin/XPlaneConnect/64/win.xpl differ diff --git a/xpcPlugin/XPlaneConnect/win.xpl b/xpcPlugin/XPlaneConnect/win.xpl index ab2526a..b94dc15 100644 Binary files a/xpcPlugin/XPlaneConnect/win.xpl and b/xpcPlugin/XPlaneConnect/win.xpl differ diff --git a/xpcPlugin/xpcPlugin/xpcPlugin.vcxproj b/xpcPlugin/xpcPlugin/xpcPlugin.vcxproj index 2c91d4e..3ed8c71 100644 --- a/xpcPlugin/xpcPlugin/xpcPlugin.vcxproj +++ b/xpcPlugin/xpcPlugin/xpcPlugin.vcxproj @@ -59,12 +59,13 @@ NotUsing Level3 Disabled - IBM=1;XPLM200;_DEBUG;_WINDOWS;_USRDLL;XPCPLUGIN_EXPORTS;%(PreprocessorDefinitions) + IBM=1;XPLM200;_DEBUG;_WINDOWS;_USRDLL;XPCPLUGIN_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) OldStyle true false - 4996 + + false MultiThreadedDebug @@ -79,7 +80,7 @@ NotUsing Level3 Disabled - IBM=1;XPLM200;_DEBUG;_WINDOWS;_USRDLL;XPCPLUGIN_EXPORTS;%(PreprocessorDefinitions) + IBM=1;XPLM200;_DEBUG;_WINDOWS;_USRDLL;XPCPLUGIN_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) OldStyle