diff --git a/CMakeLists.txt b/CMakeLists.txt index b9ff2961f..071979d81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -602,6 +602,7 @@ target_link_libraries(clonk ) target_link_libraries(c4group ${ZLIB_LIBRARIES} + ${WS2} ${OPENSSL} ) diff --git a/engine/inc/C4Application.h b/engine/inc/C4Application.h index 7805d0245..42ac67a6f 100644 --- a/engine/inc/C4Application.h +++ b/engine/inc/C4Application.h @@ -90,6 +90,7 @@ class C4Application: public CStdApp bool OpenGame(); bool PreInit(); static BOOL ProcessCallback(const char *szMessage, int iProcess); + void ApplyResolutionConstraints(); virtual void OnCommand(const char *szCmd); diff --git a/engine/inc/C4Config.h b/engine/inc/C4Config.h index 622b03407..1e5533b13 100644 --- a/engine/inc/C4Config.h +++ b/engine/inc/C4Config.h @@ -141,8 +141,9 @@ class C4ConfigGraphics int32_t RenderInactiveEM; // draw vieports even if inactive in CPEM int32_t DisableGamma; int32_t Monitor; // monitor index to play on - int32_t FireParticles; // draw extended fire particles if enabled (defualt on) + int32_t FireParticles; // draw extended fire particles if enabled (default on) int32_t MaxRefreshDelay; // minimum time after which graphics should be refreshed (ms) + int32_t EnableShaders; // enable pixel shaders on engines that support them void CompileFunc(StdCompiler *pComp); void ApplyResolutionConstraints(); }; diff --git a/engine/sec/C4ConfigShareware.cpp b/engine/sec/C4ConfigShareware.cpp index 02ed99aff..403106659 100644 --- a/engine/sec/C4ConfigShareware.cpp +++ b/engine/sec/C4ConfigShareware.cpp @@ -486,7 +486,7 @@ void C4ConfigShareware::ClearRegistrationError() RegistrationError.Clear(); } -bool C4ConfigShareware::IsConfidentialData(const char *szInput, bool fShowWarningMessage) +bool C4ConfigShareware::IsConfidentialData(const char *szInput) { // safety if (!szInput) return false; @@ -496,10 +496,12 @@ bool C4ConfigShareware::IsConfidentialData(const char *szInput, bool fShowWarnin const char *szWebCode = GetRegistrationData("WebCode"); if (szWebCode && *szWebCode) if (SSearchNoCase(szInput, szWebCode)) { - if (fShowWarningMessage && ::pGUI) - ::pGUI->ShowErrorMessage(LoadResStr("IDS_ERR_WARNINGYOUWERETRYINGTOSEN")); +/* if (fShowWarningMessage && ::pGUI) + ::pGUI->ShowErrorMessage(LoadResStr("IDS_ERR_WARNINGYOUWERETRYINGTOSEN"));*/ return true; } // all OK return false; } + +C4ConfigShareware Config; diff --git a/engine/sec/C4ConfigShareware.h b/engine/sec/C4ConfigShareware.h index 4e38d7ad1..c31a2ad02 100644 --- a/engine/sec/C4ConfigShareware.h +++ b/engine/sec/C4ConfigShareware.h @@ -54,7 +54,7 @@ class C4ConfigShareware: public C4Config const char* GetKeyPath(); StdStrBuf GetKeyMD5(); // checks for phising attacks: Return true if input contains user's webcode - bool IsConfidentialData(const char *szInput, bool fShowWarningMessage); + bool IsConfidentialData(const char *szInput); protected: StdStrBuf RegistrationError; bool HandleError(const char *strMessage); diff --git a/engine/src/C4Application.cpp b/engine/src/C4Application.cpp index eacdefd3f..ecdd27308 100644 --- a/engine/src/C4Application.cpp +++ b/engine/src/C4Application.cpp @@ -157,6 +157,27 @@ bool C4Application::DoInit() return true; #endif + DDrawCfg.Shader = Config.Graphics.EnableShaders; + switch (Config.Graphics.Engine) { +#ifdef USE_DIRECTX + case GFXENGN_DIRECTX: + case GFXENGN_DIRECTXS: + // Direct3D + DDrawCfg.Set(Config.Graphics.NewGfxCfg, (float) Config.Graphics.BlitOff/100.0f); + break; +#endif +#ifdef USE_GL + case GFXENGN_OPENGL: + // OpenGL + DDrawCfg.Set(Config.Graphics.NewGfxCfgGL, (float) Config.Graphics.BlitOffGL/100.0f); + break; +#endif + default: ; // Always have at least one statement + } + + // Fixup resolution + ApplyResolutionConstraints(); + // activate Active=TRUE; @@ -219,6 +240,38 @@ bool C4Application::DoInit() return true; } + +void C4Application::ApplyResolutionConstraints() +{ + // Enumerate display modes + int32_t idx = 0, iXRes, iYRes, iBitDepth; + int32_t best_match = -1; + uint32_t best_delta = ~0; + int32_t ResX = Config.Graphics.ResX, ResY = Config.Graphics.ResY, BitDepth = Config.Graphics.BitDepth; + while (GetIndexedDisplayMode(idx++, &iXRes, &iYRes, &iBitDepth, Config.Graphics.Monitor)) + { + uint32_t delta = std::abs(ResX*ResY - iXRes*iYRes); + if (!delta && iBitDepth == BitDepth) + return; // Exactly the expected mode + if (delta < best_delta) + { + // Better match than before + best_match = idx; + best_delta = delta; + } + } + if (best_match != -1) + { + // Apply next-best mode + GetIndexedDisplayMode(best_match, &iXRes, &iYRes, &iBitDepth, Config.Graphics.Monitor); + if (iXRes != ResX || iYRes != ResY) + // Don't warn if only bit depth changes + // Also, lang table not loaded yet + LogF("Warning: The selected resolution %dx%d is not available and has been changed to %dx%d.", ResX, ResY, iXRes, iYRes); + ResX = iXRes; ResY = iYRes; + } +} + bool C4Application::PreInit() { if (!Game.PreInit()) return false; diff --git a/engine/src/C4ChatDlg.cpp b/engine/src/C4ChatDlg.cpp index 79c52b033..d20bbd406 100644 --- a/engine/src/C4ChatDlg.cpp +++ b/engine/src/C4ChatDlg.cpp @@ -836,7 +836,11 @@ bool C4ChatControl::ProcessInput(const char *szInput, ChatSheet *pChatSheet) // safety if (!szInput || !*szInput || !pChatSheet) return fResult; // check confidential data - if (Config.IsConfidentialData(szInput, true)) return fResult; + if (Config.IsConfidentialData(szInput)) + { + pChatSheet->DoError(LoadResStr("IDS_ERR_WARNINGYOUWERETRYINGTOSEN")); + return fResult; + } // command? if (*szInput == '/' && !SEqual2NoCase(szInput + 1, "me ")) { diff --git a/engine/src/C4Config.cpp b/engine/src/C4Config.cpp index eeecc9242..fac252cfc 100644 --- a/engine/src/C4Config.cpp +++ b/engine/src/C4Config.cpp @@ -33,7 +33,6 @@ #ifndef BIG_C4INCLUDE #include #include -#include #include #include #endif @@ -162,7 +161,7 @@ void C4ConfigGraphics::CompileFunc(StdCompiler *pComp) pComp->Value(mkNamingAdapt(Monitor, "Monitor", 0 )); // 0 = D3DADAPTER_DEFAULT pComp->Value(mkNamingAdapt(FireParticles, "FireParticles", TRUE )); pComp->Value(mkNamingAdapt(MaxRefreshDelay, "MaxRefreshDelay", 30 )); - pComp->Value(mkNamingAdapt(DDrawCfg.Shader, "Shader", 0 ,false, true)); + pComp->Value(mkNamingAdapt(EnableShaders, "Shader", 0 ,false, true)); } void C4ConfigSound::CompileFunc(StdCompiler *pComp) @@ -481,33 +480,25 @@ BOOL C4Config::Load(BOOL forceWorkingDirectory, const char *szConfigFile) // Config postinit General.DeterminePaths(forceWorkingDirectory); General.AdoptOldSettings(); - #ifdef HAVE_WINSOCK - bool fWinSock = AcquireWinSock(); - #endif +#ifdef HAVE_WINSOCK + // Setup WS manually, so c4group doesn't depend on C4NetIO + WSADATA wsadata; + bool fWinSock = !WSAStartup(WINSOCK_VERSION, &wsadata); +#endif if (SEqual(Network.LocalName.getData(), "Unknown")) { char LocalName[25+1]; *LocalName = 0; gethostname(LocalName, 25); if (*LocalName) Network.LocalName.Copy(LocalName); } - #ifdef HAVE_WINSOCK - if (fWinSock) ReleaseWinSock(); - #endif +#ifdef HAVE_WINSOCK + if (fWinSock) WSACleanup(); +#endif General.DefaultLanguage(); #if defined USE_GL && !defined USE_DIRECTX if (Graphics.Engine == GFXENGN_DIRECTX || Graphics.Engine == GFXENGN_DIRECTXS) Graphics.Engine = GFXENGN_OPENGL; #endif -#ifdef USE_DIRECTX - // set ddraw config - if (Graphics.Engine == GFXENGN_DIRECTX || Graphics.Engine == GFXENGN_DIRECTXS) - // Direct3D - DDrawCfg.Set(Graphics.NewGfxCfg, (float) Graphics.BlitOff/100.0f); - else -#endif - // OpenGL - DDrawCfg.Set(Graphics.NewGfxCfgGL, (float) Graphics.BlitOffGL/100.0f); - Graphics.ApplyResolutionConstraints(); // Warning against invalid ports if (Config.Network.PortTCP>0 && Config.Network.PortTCP == Config.Network.PortRefServer) { @@ -595,36 +586,6 @@ BOOL C4Config::Save() return TRUE; } -void C4ConfigGraphics::ApplyResolutionConstraints() -{ - // Enumerate display modes - int32_t idx = 0, iXRes, iYRes, iBitDepth; - int32_t best_match = -1; - uint32_t best_delta = ~0; - while (Application.GetIndexedDisplayMode(idx++, &iXRes, &iYRes, &iBitDepth, Config.Graphics.Monitor)) - { - uint32_t delta = std::abs(ResX*ResY - iXRes*iYRes); - if (!delta && iBitDepth == BitDepth) - return; // Exactly the expected mode - if (delta < best_delta) - { - // Better match than before - best_match = idx; - best_delta = delta; - } - } - if (best_match != -1) - { - // Apply next-best mode - Application.GetIndexedDisplayMode(best_match, &iXRes, &iYRes, &iBitDepth, Config.Graphics.Monitor); - if (iXRes != ResX || iYRes != ResY) - // Don't warn if only bit depth changes - // Also, lang table not loaded yet - LogF("Warning: The selected resolution %dx%d is not available and has been changed to %dx%d.", ResX, ResY, iXRes, iYRes); - ResX = iXRes; ResY = iYRes; - } -} - void C4ConfigGeneral::DeterminePaths(BOOL forceWorkingDirectory) { #ifdef _WIN32 diff --git a/engine/src/C4GameLobby.cpp b/engine/src/C4GameLobby.cpp index b1a51c049..23954ed4e 100644 --- a/engine/src/C4GameLobby.cpp +++ b/engine/src/C4GameLobby.cpp @@ -449,7 +449,11 @@ C4GUI::Edit::InputResult MainDlg::OnChatInput(C4GUI::Edit *edt, bool fPasting, b ::MessageInput.StoreBackBuffer(szInputText); bool fProcessed = false; // check confidential data - if (Config.IsConfidentialData(szInputText, true)) fProcessed = true; + if (Config.IsConfidentialData(szInputText)) + { + ::pGUI->ShowErrorMessage(LoadResStr("IDS_ERR_WARNINGYOUWERETRYINGTOSEN")); + fProcessed = true; + } // CAUTION when implementing special commands (like /quit) here: // those must not be executed when text is pasted, because that could crash the GUI system // when there are additional lines to paste, but the edit field is destructed by the command diff --git a/engine/src/C4MessageInput.cpp b/engine/src/C4MessageInput.cpp index 5edfd99a3..5a8b077b1 100644 --- a/engine/src/C4MessageInput.cpp +++ b/engine/src/C4MessageInput.cpp @@ -37,7 +37,7 @@ #include #include #include -#include v +#include #endif #include @@ -132,8 +132,9 @@ C4GUI::Edit::InputResult C4ChatInputDialog::OnChatInput(C4GUI::Edit *edt, bool f // Store to back buffer ::MessageInput.StoreBackBuffer(szInputText); // check confidential data - even for object input (script triggered), webcode should not be pasted here - if (Config.IsConfidentialData(szInputText, true)) + if (Config.IsConfidentialData(szInputText)) { + ::pGUI->ShowErrorMessage(LoadResStr("IDS_ERR_WARNINGYOUWERETRYINGTOSEN")); szInputText = ""; } // script queried input? diff --git a/engine/src/C4WinMain.cpp b/engine/src/C4WinMain.cpp index 6b9ee1d4a..19dca8f10 100644 --- a/engine/src/C4WinMain.cpp +++ b/engine/src/C4WinMain.cpp @@ -36,7 +36,6 @@ C4Application Application; C4Console Console; C4FullScreen FullScreen; C4Game Game; -C4ConfigShareware Config; #ifdef _WIN32 diff --git a/group/c4group_ng.cpp b/group/c4group_ng.cpp index ba72f8a64..eabec7280 100644 --- a/group/c4group_ng.cpp +++ b/group/c4group_ng.cpp @@ -61,22 +61,17 @@ bool Log(const char *msg) { printf("%s\n", msg); return 1; } -BOOL LogF(const char *strMessage, ...) { - va_list args; - va_start(args, strMessage); - // Compose formatted message - StdStrBuf Buf; - Buf.FormatV(strMessage, args); - // Log - return Log(Buf.getData()); -} -BOOL DebugLogF(const char *strMessage ...) -{ - va_list args; va_start(args, strMessage); - StdStrBuf Buf; - Buf.FormatV(strMessage, args); - return Log(Buf.getData()); -} +#define IMPLEMENT_LOGF(func) \ + BOOL func(const char *msg, ...) { \ + va_list args; va_start(args, msg); \ + StdStrBuf Buf; \ + Buf.FormatV(msg, args); \ + return Log(Buf.getData()); \ + } + +IMPLEMENT_LOGF(DebugLogF) +IMPLEMENT_LOGF(LogF) +IMPLEMENT_LOGF(LogSilentF) bool ProcessGroup(const char *FilenamePar) { @@ -402,8 +397,10 @@ int UnregisterShellExtensions() { } int main(int argc, char *argv[]) { +#ifndef WIN32 // Always line buffer mode, even if the output is not sent to a terminal - setvbuf(stdout, NULL, _IOLBF, 0); + setvbuf(stdout, NULL, _IOLBF, 0); +#endif // Scan options int iFirstGroup = 0; for (int i = 1; i < argc; ++i) {