From 5984fda8a1c5739e205abb02544d60468e65a81a Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 5 Apr 2021 21:41:11 +1000 Subject: [PATCH 1/5] - PlayerAngle: Repair issues with `addadjustment()` method following changes in 4ffe0044832410f8c8650001f344abe1cc637cec that were affecting negative input. --- source/core/binaryangle.h | 4 +++- source/core/gameinput.h | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/core/binaryangle.h b/source/core/binaryangle.h index bec19e891..3cdc8dc49 100644 --- a/source/core/binaryangle.h +++ b/source/core/binaryangle.h @@ -122,6 +122,7 @@ class lookangle friend constexpr lookangle bamlook(int32_t v); friend constexpr lookangle q16look(int32_t v); friend constexpr lookangle buildlook(int32_t v); + friend lookangle buildflook(double v); friend lookangle radlook(double v); friend lookangle deglook(double v); @@ -224,7 +225,8 @@ public: inline constexpr lookangle bamlook(int32_t v) { return lookangle(v); } inline constexpr lookangle q16look(int32_t v) { return lookangle(v << 5); } inline constexpr lookangle buildlook(int32_t v) { return lookangle(v << BAMBITS); } -inline lookangle radlook(double v) { return lookangle(xs_CRoundToUInt(v * (0x80000000u / pi::pi()))); } +inline lookangle buildflook(double v) { return lookangle(xs_CRoundToInt(v * BAMUNIT)); } +inline lookangle radlook(double v) { return lookangle(xs_CRoundToInt(v * (0x80000000u / pi::pi()))); } inline lookangle deglook(double v) { return lookangle(FloatToAngle(v)); } inline FSerializer &Serialize(FSerializer &arc, const char *key, lookangle &obj, lookangle *defval) diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 2fdc94b9a..39f9a12ff 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -149,22 +149,22 @@ struct PlayerAngle void addadjustment(int value) { - __addadjustment(buildang(value)); + __addadjustment(buildlook(value)); } void addadjustment(double value) { - __addadjustment(buildfang(value)); + __addadjustment(buildflook(value)); } void addadjustment(lookangle value) { - __addadjustment(bamang(value.asbam())); + __addadjustment(value); } void addadjustment(binangle value) { - __addadjustment(value); + __addadjustment(bamlook(value.asbam())); } void resetadjustment() @@ -254,7 +254,7 @@ private: binangle target; double adjustment; - void __addadjustment(binangle value) + void __addadjustment(lookangle value) { if (!SyncInput()) { From bfcedc2177ccb1b65d27d40f49adab18414f3b85 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 6 Apr 2021 00:56:34 +0200 Subject: [PATCH 2/5] - autodetect .inis when loading Blood mods. This works as long as the loaded mods have one single .ini file in them - in that case it is assumed that it is supposed to replace blood.ini, which will allow dragging & dropping such archives without further user intervention. --- source/games/blood/src/levels.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/source/games/blood/src/levels.cpp b/source/games/blood/src/levels.cpp index ad1cd6ad9..462fbe316 100644 --- a/source/games/blood/src/levels.cpp +++ b/source/games/blood/src/levels.cpp @@ -115,6 +115,28 @@ void levelLoadMapInfo(IniFile *pIni, MapRecord *pLevelInfo, const char *pzSectio static const char* DefFile(void) { + int found = -1; + if (userConfig.DefaultCon.IsEmpty() || userConfig.DefaultCon.CompareNoCase("blood.ini") == 0) + { + int numlumps = fileSystem.GetNumEntries(); + for (int i = numlumps - 1; i >= 0; i--) + { + if (fileSystem.GetFileContainer(i) <= fileSystem.GetMaxIwadNum()) break; + FString fn = fileSystem.GetFileFullName(i, false); + FString ext = fn.Right(4); + if (ext.CompareNoCase(".ini") == 0) + { + if (fileSystem.CheckNumForFullName(fn) != i) continue; + if (found == -1) found = i; + else + { + found = -1; + break; + } + } + } + } + if (found >= 0) return fileSystem.GetFileFullName(found); // The command line parser stores this in the CON field. return userConfig.DefaultCon.IsNotEmpty() ? userConfig.DefaultCon.GetChars() : "blood.ini"; } From fc314b6616e14b83a40e8dca9cbe94caa2e4f08c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 6 Apr 2021 01:06:03 +0200 Subject: [PATCH 3/5] - allow loading Zips where all content is in a subdirectory. The same logic as in GZDoom applies: The root must not have any other content and the subdirectory must contain identifiable game content. Some handling was also added to strip out macOS resource fork folders because they can contain data that can confuse file detection. --- source/common/filesystem/file_zip.cpp | 16 ++++++++++++---- source/core/initfs.cpp | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/source/common/filesystem/file_zip.cpp b/source/common/filesystem/file_zip.cpp index 00de98cdc..2adca1160 100644 --- a/source/common/filesystem/file_zip.cpp +++ b/source/common/filesystem/file_zip.cpp @@ -233,12 +233,14 @@ bool FZipFile::Open(bool quiet, LumpFilterInfo* filter) } name.ToLower(); + if (name.IndexOf("__macosx") == 0) + continue; // skip Apple garbage. At this stage only the root folder matters, if (i == 0) { // check for special names, if one of these gets found this must be treated as a normal zip. bool isspecial = name.IndexOf("/") < 0 || (filter && filter->reservedFolders.Find(name) < filter->reservedFolders.Size()); if (isspecial) break; - name0 = name; + name0 = name.Left(name.LastIndexOf("/")+1); } else { @@ -252,7 +254,7 @@ bool FZipFile::Open(bool quiet, LumpFilterInfo* filter) // at least one of the more common definition lumps must be present. for (auto &p : filter->requiredPrefixes) { - if (name.IndexOf(name0 + p) == 0) + if (name.IndexOf(name0 + p) == 0 || name.LastIndexOf(p) == name.Len() - strlen(p)) { foundspeciallump = true; break; @@ -272,7 +274,6 @@ bool FZipFile::Open(bool quiet, LumpFilterInfo* filter) int len = LittleShort(zip_fh->NameLength); FString name(dirptr + sizeof(FZipCentralDirectoryInfo), len); - if (name0.IsNotEmpty()) name = name.Mid(name0.Len()); dirptr += sizeof(FZipCentralDirectoryInfo) + LittleShort(zip_fh->NameLength) + LittleShort(zip_fh->ExtraLength) + @@ -284,7 +285,14 @@ bool FZipFile::Open(bool quiet, LumpFilterInfo* filter) if (!quiet) Printf(TEXTCOLOR_RED "\n%s: Central directory corrupted.", FileName.GetChars()); return false; } - + + if (name.IndexOf("__macosx") == 0 || name.IndexOf("__MACOSX") == 0) + { + skipped++; + continue; // Weed out Apple's resource fork garbage right here because it interferes with safe operation. + } + if (name0.IsNotEmpty()) name = name.Mid(name0.Len()); + // skip Directories if (name.IsEmpty() || (name.Back() == '/' && LittleLong(zip_fh->UncompressedSize) == 0)) { diff --git a/source/core/initfs.cpp b/source/core/initfs.cpp index f18fd50d3..6910d2cdf 100644 --- a/source/core/initfs.cpp +++ b/source/core/initfs.cpp @@ -274,6 +274,18 @@ static void DeleteStuff(FileSystem &fileSystem, const TArray& deletelum // // //========================================================================== +const char* iwad_folders[13] = { "textures/", "hires/", "sounds/", "music/", "maps/" }; +const char* iwad_reserved_duke[12] = { ".map", ".con", "menudef", "gldefs", "zscript", "maps/", nullptr }; +const char* iwad_reserved_blood[12] = { ".map", ".ini", "menudef", "gldefs", "zscript", "maps/", nullptr }; +const char* iwad_reserved_sw[12] = { ".map", "swcustom.txt", "menudef", "gldefs", "zscript", "maps/", nullptr }; +const char* iwad_reserved_ex[12] = { ".map", "menudef", "gldefs", "zscript", "maps/", nullptr }; + +const char** iwad_reserved() +{ + return (g_gameType & GAMEFLAG_PSEXHUMED) ? iwad_reserved_ex : + (g_gameType & GAMEFLAG_SW) ? iwad_reserved_sw : + (g_gameType & GAMEFLAG_BLOOD) ? iwad_reserved_blood : iwad_reserved_duke; +} void InitFileSystem(TArray& groups) { @@ -374,6 +386,8 @@ void InitFileSystem(TArray& groups) } todelete.Append(userConfig.toBeDeleted); LumpFilterInfo lfi; + for (auto p : iwad_folders) lfi.reservedFolders.Push(p); + for (auto p = iwad_reserved(); *p; p++) lfi.requiredPrefixes.Push(*p); lfi.dotFilter = LumpFilter; From cbe25d9d6bc9b3b1acde13a7466df556ae87226d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 6 Apr 2021 12:06:03 +0200 Subject: [PATCH 4/5] - Blood: disable look left and look right in the classic key configuration. --- source/common/console/c_bind.cpp | 6 ++++++ wadsrc/static/filter/blood/engine/origbinds.txt | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/source/common/console/c_bind.cpp b/source/common/console/c_bind.cpp index 1aad2d255..fa94d1e72 100644 --- a/source/common/console/c_bind.cpp +++ b/source/common/console/c_bind.cpp @@ -696,6 +696,12 @@ void ReadBindings(int lump, bool override) dest = &AutomapBindings; sc.MustGetString(); } + else if (sc.Compare("unbind")) + { + sc.MustGetString(); + dest->UnbindKey(sc.String); + continue; + } key = GetConfigKeyFromName(sc.String); sc.MustGetString(); dest->SetBind(key, sc.String, override); diff --git a/wadsrc/static/filter/blood/engine/origbinds.txt b/wadsrc/static/filter/blood/engine/origbinds.txt index 85f93e3dc..e13f235d1 100644 --- a/wadsrc/static/filter/blood/engine/origbinds.txt +++ b/wadsrc/static/filter/blood/engine/origbinds.txt @@ -8,3 +8,8 @@ X "+Alt_Fire" J "useitem 4" M "useitem 1" Mouse2 "+Alt_Fire" + +unbind KP0 +unbind KP. +unbind DEL +unbind INS From 424c0ce3f49e188c3fc2bd4adb834e97a559453e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 6 Apr 2021 15:07:12 +0200 Subject: [PATCH 5/5] - testing some script parser improvements. --- source/build/src/defs.cpp | 11 +++----- source/common/engine/sc_man.h | 7 +++++ source/core/parsefuncs.h | 48 +++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 source/core/parsefuncs.h diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index 0ed7faeb5..99beccbb3 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -17,6 +17,7 @@ #include "gamecontrol.h" #include "palettecontainer.h" #include "mapinfo.h" +#include "parsefuncs.h" int tileSetHightileReplacement(int picnum, int palnum, const char* filename, float alphacut, float xscale, float yscale, float specpower, float specfactor, uint8_t flags); int tileSetSkybox(int picnum, int palnum, const char** facenames, int flags); @@ -655,15 +656,9 @@ static int32_t defsparser(scriptfile *script) break; } case T_ANIMTILERANGE: - { - SetAnim set; - if (scriptfile_getsymbol(script,&set.tile1)) break; - if (scriptfile_getsymbol(script,&set.tile2)) break; - if (scriptfile_getsymbol(script,&set.speed)) break; - if (scriptfile_getsymbol(script,&set.type)) break; - processSetAnim("animtilerange", pos, set); + parseAnimTileRange(*script, pos); break; - } + case T_TILEFROMTEXTURE: { auto texturepos = scriptfile_getposition(script); diff --git a/source/common/engine/sc_man.h b/source/common/engine/sc_man.h index 6c37806a8..3a894fcb3 100644 --- a/source/common/engine/sc_man.h +++ b/source/common/engine/sc_man.h @@ -113,6 +113,13 @@ public: void MustGetNumber(bool evaluate = false); bool CheckNumber(bool evaluate = false); + bool GetNumber(int& var, bool evaluate = false) + { + if (!GetNumber(evaluate)) return false; + var = Number; + return true; + } + bool GetFloat(bool evaluate = false); void MustGetFloat(bool evaluate = false); bool CheckFloat(bool evaluate = false); diff --git a/source/core/parsefuncs.h b/source/core/parsefuncs.h new file mode 100644 index 000000000..05b3aa87b --- /dev/null +++ b/source/core/parsefuncs.h @@ -0,0 +1,48 @@ + +/* +** parsefuncs.h +** handlers for .def parser +** only to be included by the actual parser +** +**--------------------------------------------------------------------------- +** Copyright 2021 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +** +*/ + + +void parseAnimTileRange(FScanner& sc, FScriptPosition& pos) +{ + SetAnim set; + if (!sc.GetNumber(set.tile1, true)) return; + if (!sc.GetNumber(set.tile2, true)) return; + if (!sc.GetNumber(set.speed, true)) return; + if (!sc.GetNumber(set.type, true)) return; + processSetAnim("animtilerange", pos, set); +} +