OSDN Git Service

[Implement] #1743 バリアント名をセーブデータに含めた
authorHourier <66951241+Hourier@users.noreply.github.com>
Thu, 6 Jan 2022 08:22:41 +0000 (17:22 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sun, 30 Jan 2022 14:51:51 +0000 (23:51 +0900)
src/core/scores.cpp
src/core/show-file.cpp
src/io/report.cpp
src/load/info-loader.cpp
src/load/load.cpp
src/save/save.cpp
src/system/angband-version.h

index 6e54866..c5c75ea 100644 (file)
@@ -181,7 +181,7 @@ errr top_twenty(PlayerType *current_player_ptr)
     char buf[32];
 
     /* Save the version */
-    sprintf(the_score.what, "%u.%u.%u", FAKE_VER_MAJOR, FAKE_VER_MINOR, FAKE_VER_PATCH);
+    sprintf(the_score.what, "%u.%u.%u", H_VER_MAJOR, H_VER_MINOR, H_VER_PATCH);
 
     /* Calculate and save the points */
     sprintf(the_score.pts, "%9ld", (long)calc_score(current_player_ptr));
@@ -289,7 +289,7 @@ errr predict_score(PlayerType *current_player_ptr)
     }
 
     /* Save the version */
-    sprintf(the_score.what, "%u.%u.%u", FAKE_VER_MAJOR, FAKE_VER_MINOR, FAKE_VER_PATCH);
+    sprintf(the_score.what, "%u.%u.%u", H_VER_MAJOR, H_VER_MINOR, H_VER_PATCH);
 
     /* Calculate and save the points */
     sprintf(the_score.pts, "%9ld", (long)calc_score(current_player_ptr));
index 00aa34f..619dd4b 100644 (file)
@@ -301,7 +301,7 @@ bool show_file(PlayerType *player_ptr, bool show_version, concptr name, concptr
             continue;
         }
 
-        prt(format(_("[変愚蛮怒 %d.%d.%d, %s, %d/%d]", "[Hengband %d.%d.%d, %s, Line %d/%d]"), FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH, caption,
+        prt(format(_("[変愚蛮怒 %d.%d.%d, %s, %d/%d]", "[Hengband %d.%d.%d, %s, Line %d/%d]"), H_VER_MAJOR, H_VER_MINOR, H_VER_PATCH, caption,
                 line, size),
             0, 0);
 
index 9dab44e..e7e4a35 100644 (file)
@@ -194,7 +194,7 @@ static bool http_post(concptr url, BUF *buf)
     curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
 
     char user_agent[64];
-    snprintf(user_agent, sizeof(user_agent), "Hengband %d.%d.%d", FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH);
+    snprintf(user_agent, sizeof(user_agent), "Hengband %d.%d.%d", H_VER_MAJOR, H_VER_MINOR, H_VER_PATCH);
     curl_easy_setopt(curl, CURLOPT_USERAGENT, user_agent);
 
     curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
index b9cddf6..b49aaf5 100644 (file)
  */
 void rd_version_info(void)
 {
-    byte fake_major = rd_byte();
+    auto tmp_major = rd_byte();
+    auto is_old_ver = (10 <= tmp_major) && (tmp_major <= 13);
+    if (tmp_major == 8) {
+        // strip_byte() だと自動ローテーションされるので手動スキップ.
+        for (auto i = 0; i < 8; i++) {
+            load_xor_byte = 0;
+            (void)rd_byte();
+        }
+
+        load_xor_byte = 0;
+        w_ptr->h_ver_major = rd_byte();
+        w_ptr->h_ver_minor = rd_byte();
+        w_ptr->h_ver_patch = rd_byte();
+        w_ptr->h_ver_extra = rd_byte();
+    } else if (is_old_ver) {
+        strip_bytes(3);
+    } else {
+        throw("Invalid version is detected!");
+    }
 
-    strip_bytes(3);
     load_xor_byte = w_ptr->sf_extra;
     v_check = 0L;
     x_check = 0L;
 
-    /* Old savefile will be version 0.0.0.3 */
-    w_ptr->h_ver_extra = rd_byte();
-    w_ptr->h_ver_patch = rd_byte();
-    w_ptr->h_ver_minor = rd_byte();
-    w_ptr->h_ver_major = rd_byte();
+    if (is_old_ver) {
+        /* Old savefile will be version 0.0.0.3 */
+        w_ptr->h_ver_extra = rd_byte();
+        w_ptr->h_ver_patch = rd_byte();
+        w_ptr->h_ver_minor = rd_byte();
+        w_ptr->h_ver_major = rd_byte();
+    }
 
     w_ptr->sf_system = rd_u32b();
     w_ptr->sf_when = rd_u32b();
@@ -37,8 +56,12 @@ void rd_version_info(void)
     loading_savefile_version = rd_u32b();
 
     /* h_ver_majorがfake_ver_majorと同じだったころへの対策 */
-    if (fake_major - w_ptr->h_ver_major < FAKE_VER_PLUS)
-        w_ptr->h_ver_major -= FAKE_VER_PLUS;
+    if (loading_savefile_version_is_older_than(10)) {
+        constexpr auto fake_ver_plus = 10;
+        if (tmp_major - w_ptr->h_ver_major < fake_ver_plus) {
+            w_ptr->h_ver_major -= fake_ver_plus;
+        }
+    }
 
     load_note(format(_("バージョン %d.%d.%d のセーブデータ(SAVE%lu形式)をロード中...", "Loading a Verison %d.%d.%d savefile (SAVE%lu format)..."),
         w_ptr->h_ver_major, w_ptr->h_ver_minor, w_ptr->h_ver_patch,
index 1e60067..fc582ab 100644 (file)
@@ -305,7 +305,7 @@ bool load_savedata(PlayerType *player_ptr, bool *new_game)
 
     bool err = false;
     int fd = -1;
-    byte fake_ver[4];
+    char tmp_ver[13]{};
     if (!err) {
         fd = fd_open(savefile, O_RDONLY);
         if (fd < 0)
@@ -316,19 +316,37 @@ bool load_savedata(PlayerType *player_ptr, bool *new_game)
     }
 
     if (!err) {
-        if (fd_read(fd, (char *)(fake_ver), 4))
+        if (fd_read(fd, (char *)(tmp_ver), 13)) {
             err = true;
+        }
 
-        if (err)
+        if (err) {
             what = _("セーブファイルを読めません", "Cannot read savefile");
-
-        (void)fd_close(fd);
+        }
     }
 
     if (!err) {
-        if (fake_ver[0] < FAKE_VER_PLUS) {
-            what = _("セーブデータが古すぎます", "Savefile version is too old");
-            err = true;
+        auto tmp_major = tmp_ver[0];
+        auto is_old_ver = (10 <= tmp_major) && (tmp_major <= 13);
+        if (tmp_major == 8) {
+            std::string variant_name(VERSION_NAME);
+            std::stringstream current_variant;
+            for (auto i = 1; i < 9; i++) {
+                current_variant << tmp_ver[i];
+            }
+
+            if (current_variant.str() != variant_name) {
+                throw(_("セーブデータのバリアントは変愚蛮怒以外です", "The variant of save data is other than Hengband!"));
+            }
+
+            w_ptr->sf_extra = tmp_ver[13];
+            (void)fd_close(fd);
+        } else if (is_old_ver) {
+            w_ptr->sf_extra = tmp_ver[3];
+            (void)fd_close(fd);
+        } else {
+            (void)fd_close(fd);
+            throw("Invalid version is detected!");
         }
     }
 
@@ -338,8 +356,6 @@ bool load_savedata(PlayerType *player_ptr, bool *new_game)
         return false;
     }
 
-    w_ptr->sf_extra = fake_ver[3];
-
     if (!err) {
         term_clear();
         if (rd_savefile(player_ptr))
index ce9042e..71b0b54 100644 (file)
@@ -57,23 +57,27 @@ static bool wr_savefile_new(PlayerType *player_ptr, save_type type)
     w_ptr->sf_system = 0L;
     w_ptr->sf_when = now;
     w_ptr->sf_saves++;
+
+    std::string tmp_variant(VERSION_NAME);
     save_xor_byte = 0;
-    wr_byte(FAKE_VER_MAJOR);
-    save_xor_byte = 0;
-    wr_byte(FAKE_VER_MINOR);
-    save_xor_byte = 0;
-    wr_byte(FAKE_VER_PATCH);
+    wr_byte(static_cast<byte>(tmp_variant.length()));
+    for (auto i = 0; i < 8; i++) {
+        auto variant_name = tmp_variant.c_str();
+        save_xor_byte = 0;
+        wr_byte(variant_name[i]);
+    }
+
     save_xor_byte = 0;
+    wr_byte(H_VER_MAJOR);
+    wr_byte(H_VER_MINOR);
+    wr_byte(H_VER_PATCH);
+    wr_byte(H_VER_EXTRA);
 
     byte tmp8u = (byte)Rand_external(256);
     wr_byte(tmp8u);
     v_stamp = 0L;
     x_stamp = 0L;
-
-    wr_byte(H_VER_EXTRA);
-    wr_byte(H_VER_PATCH);
-    wr_byte(H_VER_MINOR);
-    wr_byte(H_VER_MAJOR);
     wr_u32b(w_ptr->sf_system);
     wr_u32b(w_ptr->sf_when);
     wr_u16b(w_ptr->sf_lives);
index 8b9fd6a..c8e074b 100644 (file)
@@ -35,18 +35,4 @@ constexpr uint32_t SAVEFILE_VERSION = 10;
  */
 #define IS_ALPHA_VERSION 1
 
-/*!
- * @brief ゲームのバージョン番号定義 / "Program Version Number" of the game
- * @details
- * 本FAKE_VERSIONそのものは未使用である。Zangと整合性を合わせるための疑似的処理のためFAKE_VER_MAJORは実値-10が該当のバージョン番号となる。
- * <pre>
- * FAKE_VER_MAJOR=1,2 were reserved for ZAngband version 1.x.x/2.x.x .
- * </pre>
- */
-#define FAKE_VER_PLUS 10 //!< 偽バージョン番号としていくつ足すか
-#define FAKE_VER_MAJOR (H_VER_MAJOR + FAKE_VER_PLUS) //!< 偽バージョン番号定義(メジャー番号) */
-#define FAKE_VER_MINOR H_VER_MINOR //!< 偽バージョン番号定義(マイナー番号) */
-#define FAKE_VER_PATCH H_VER_PATCH //!< 偽バージョン番号定義(パッチ番号) */
-#define FAKE_VER_EXTRA H_VER_EXTRA //!< 偽バージョン番号定義(エクストラ番号) */
-
 void put_version(char *buf);