This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch debian/master
in repository openjk.

commit 4142bd9460b40822ce610e532cc3910d2cdcfe39
Author: bibendovsky <[email protected]>
Date:   Sun Jul 31 20:03:59 2016 +0300

    JO: Fix loading/saving of GHOUL2 and timers
---
 code/game/G_Timer.cpp                 |    2 +
 code/qcommon/q_shared.h               |   35 +
 code/rd-vanilla/G2_misc.cpp           |   21 +-
 codeJK2/game/G_Timer.cpp              |    2 +
 shared/qcommon/ojk_i_saved_game.h     |  763 ++++++++++-----------
 shared/qcommon/ojk_i_saved_game_fwd.h |  418 +++++------
 shared/qcommon/ojk_saved_game.cpp     | 1219 +++++++++++++++++----------------
 shared/qcommon/ojk_saved_game.h       |  228 +++---
 8 files changed, 1388 insertions(+), 1300 deletions(-)

diff --git a/code/game/G_Timer.cpp b/code/game/G_Timer.cpp
index e66ae8c..c7f7b44 100644
--- a/code/game/G_Timer.cpp
+++ b/code/game/G_Timer.cpp
@@ -244,6 +244,8 @@ void TIMER_Load( void )
                 sg_buffer_size,
                 tempBuffer);
 
+                       tempBuffer[sg_buffer_size] = '\0';
+
             ::gi.saved_game->read_chunk<int32_t>(
                 INT_ID('T','D','T','A'),
                 time);
diff --git a/code/qcommon/q_shared.h b/code/qcommon/q_shared.h
index ed87688..83a92dd 100644
--- a/code/qcommon/q_shared.h
+++ b/code/qcommon/q_shared.h
@@ -1378,14 +1378,24 @@ typedef struct {
 
 
 #define        MAX_MODELS                      256
+
+#ifdef JK2_MODE
+#define MAX_SOUNDS (256)
+#else
 #define        MAX_SOUNDS                      380
+#endif // JK2_MODE
 
 #define MAX_SUB_BSP                    32
 
 #define        MAX_SUBMODELS           512             // nine bits
 
 #define MAX_FX                         128
+
+#ifdef JK2_MODE
+#define MAX_WORLD_FX (4)
+#else
 #define MAX_WORLD_FX           66              // was 16 // was 4
+#endif // JK2_MODE
 
 /*
 Ghoul2 Insert Start
@@ -1395,7 +1405,11 @@ Ghoul2 Insert Start
 Ghoul2 Insert End
 */
 
+#ifdef JK2_MODE
+#define MAX_CONFIGSTRINGS (1024)
+#else
 #define        MAX_CONFIGSTRINGS       1300//1024 //rww - I had to up this for 
terrains
+#endif // JK2_MODE
 
 // these are the only configstrings that the system reserves, all the
 // other ones are strictly for servergame to clientgame communication
@@ -1416,19 +1430,40 @@ Ghoul2 Insert End
 
 #define        CS_MODELS                       10
 
+#ifndef JK2_MODE
 #define        CS_SKYBOXORG            (CS_MODELS+MAX_MODELS)          //rww - 
skybox info
+#endif // !JK2_MODE
 
+#ifdef JK2_MODE
+#define CS_SOUNDS (CS_MODELS + MAX_MODELS)
+#else
 #define        CS_SOUNDS                       (CS_SKYBOXORG+1)
+#endif // JK2_MODE
+
+#ifdef JK2_MODE
+#define CS_PLAYERS (CS_SOUNDS + MAX_SOUNDS)
+#else
 #ifdef BASE_SAVE_COMPAT
 #define CS_RESERVED1           (CS_SOUNDS+MAX_SOUNDS) // reserved field for 
base compat from immersion removal
 #define        CS_PLAYERS                      (CS_RESERVED1 + 96)
 #else
 #define        CS_PLAYERS                      (CS_SOUNDS+MAX_SOUNDS)
 #endif
+#endif // JK2_MODE
+
 #define        CS_LIGHT_STYLES         (CS_PLAYERS+MAX_CLIENTS)
+
+#ifndef JK2_MODE
 #define CS_TERRAINS                    (CS_LIGHT_STYLES + (MAX_LIGHT_STYLES*3))
 #define CS_BSP_MODELS          (CS_TERRAINS + MAX_TERRAINS)
+#endif // !JK2_MODE
+
+#ifdef JK2_MODE
+#define CS_EFFECTS (CS_LIGHT_STYLES + (MAX_LIGHT_STYLES * 3))
+#else
 #define CS_EFFECTS                     (CS_BSP_MODELS + 
MAX_SUB_BSP)//(CS_LIGHT_STYLES + (MAX_LIGHT_STYLES*3))
+#endif // JK2_MODE
+
 /*
 Ghoul2 Insert Start
 */
diff --git a/code/rd-vanilla/G2_misc.cpp b/code/rd-vanilla/G2_misc.cpp
index 6a0111c..436c4a6 100644
--- a/code/rd-vanilla/G2_misc.cpp
+++ b/code/rd-vanilla/G2_misc.cpp
@@ -1788,13 +1788,16 @@ void G2_SaveGhoul2Models(
 
     // is there anything to save?
     if (!ghoul2.IsValid() || ghoul2.size() == 0) {
+        const int zero_size = 0;
+
 #ifdef JK2_MODE
+               ::ri.saved_game->write<int32_t>(
+                       zero_size);
+
         ::ri.saved_game->write_chunk_and_size<int32_t>(
-            INT_ID('G', 'L', 'S', '2'),
+            INT_ID('G', 'L', '2', 'S'),
             INT_ID('G', 'H', 'L', '2'));
 #else
-        const int zero_size = 0;
-
         ::ri.saved_game->write_chunk<int32_t>(
             INT_ID('G', 'H', 'L', '2'),
             zero_size); //write out a zero buffer
@@ -1855,7 +1858,7 @@ void G2_SaveGhoul2Models(
 
 #ifdef JK2_MODE
     ::ri.saved_game->write_chunk_and_size<int32_t>(
-        INT_ID('G', 'L', 'S', '2'),
+        INT_ID('G', 'L', '2', 'S'),
         INT_ID('G', 'H', 'L', '2'));
 #else
     ::ri.saved_game->write_chunk(
@@ -1873,9 +1876,19 @@ void G2_LoadGhoul2Model(
     // first thing, lets see how many ghoul2 models we have, and resize our 
buffers accordingly
     auto model_count = 0;
 
+#ifdef JK2_MODE
+       if (::ri.saved_game->get_buffer_size() > 0)
+       {
+#endif // JK2_MODE
+
     ::ri.saved_game->read<int32_t>(
         model_count);
 
+#ifdef JK2_MODE
+       }
+#endif // JK2_MODE
+
+
     ghoul2.resize(
         model_count);
 
diff --git a/codeJK2/game/G_Timer.cpp b/codeJK2/game/G_Timer.cpp
index 1896e48..34246ea 100644
--- a/codeJK2/game/G_Timer.cpp
+++ b/codeJK2/game/G_Timer.cpp
@@ -259,6 +259,8 @@ void TIMER_Load( void )
                 tempBuffer,
                 length);
 
+                       tempBuffer[length] = '\0';
+
             ::gi.saved_game->read_chunk<int32_t>(
                 INT_ID('T','D','T','A'),
                 time);
diff --git a/shared/qcommon/ojk_i_saved_game.h 
b/shared/qcommon/ojk_i_saved_game.h
index cb83e41..ed8eaed 100644
--- a/shared/qcommon/ojk_i_saved_game.h
+++ b/shared/qcommon/ojk_i_saved_game.h
@@ -13,7 +13,8 @@
 #include "ojk_scope_guard.h"
 
 
-namespace ojk {
+namespace ojk
+{
 
 
 // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@@ -36,32 +37,32 @@ inline ISavedGame::~ISavedGame()
 
 template<typename TSrc, typename TDst>
 void ISavedGame::read_chunk(
-    const ChunkId chunk_id,
-    TDst& dst_value)
+       const ChunkId chunk_id,
+       TDst& dst_value)
 {
-    read_chunk(
-        chunk_id);
+       read_chunk(
+               chunk_id);
 
-    read<TSrc>(
-        dst_value);
+       read<TSrc>(
+               dst_value);
 
-    ensure_all_data_read();
+       ensure_all_data_read();
 }
 
 template<typename TSrc, typename TDst>
 void ISavedGame::read_chunk(
-    const ChunkId chunk_id,
-    TDst* dst_values,
-    int dst_count)
+       const ChunkId chunk_id,
+       TDst* dst_values,
+       int dst_count)
 {
-    read_chunk(
-        chunk_id);
+       read_chunk(
+               chunk_id);
 
-    read<TSrc>(
-        dst_values,
-        dst_count);
+       read<TSrc>(
+               dst_values,
+               dst_count);
 
-    ensure_all_data_read();
+       ensure_all_data_read();
 }
 
 // read_chunk
@@ -73,53 +74,53 @@ void ISavedGame::read_chunk(
 
 template<typename TSize>
 void ISavedGame::write_chunk_and_size(
-    const ChunkId size_chunk_id,
-    const ChunkId data_chunk_id)
+       const ChunkId size_chunk_id,
+       const ChunkId data_chunk_id)
 {
-    save_buffer();
+       save_buffer();
 
-    auto data_size = get_buffer_size();
+       auto data_size = get_buffer_size();
 
-    reset_buffer();
+       reset_buffer();
 
-    write_chunk<TSize>(
-        size_chunk_id,
-        data_size);
+       write_chunk<TSize>(
+               size_chunk_id,
+               data_size);
 
-    load_buffer();
+       load_buffer();
 
-    write_chunk(
-        data_chunk_id);
+       write_chunk(
+               data_chunk_id);
 }
 
 template<typename TDst, typename TSrc>
 void ISavedGame::write_chunk(
-    const ChunkId chunk_id,
-    const TSrc& src_value)
+       const ChunkId chunk_id,
+       const TSrc& src_value)
 {
-    reset_buffer();
+       reset_buffer();
 
-    write<TDst>(
-        src_value);
+       write<TDst>(
+               src_value);
 
-    write_chunk(
-        chunk_id);
+       write_chunk(
+               chunk_id);
 }
 
 template<typename TDst, typename TSrc>
 void ISavedGame::write_chunk(
-    const ChunkId chunk_id,
-    const TSrc* src_values,
-    int src_count)
+       const ChunkId chunk_id,
+       const TSrc* src_values,
+       int src_count)
 {
-    reset_buffer();
+       reset_buffer();
 
-    write<TDst>(
-        src_values,
-        src_count);
+       write<TDst>(
+               src_values,
+               src_count);
 
-    write_chunk(
-        chunk_id);
+       write_chunk(
+               chunk_id);
 }
 
 // write_chunk
@@ -131,137 +132,137 @@ void ISavedGame::write_chunk(
 
 template<typename TSrc, typename TDst>
 void ISavedGame::read(
-    TDst& dst_value)
+       TDst& dst_value)
 {
-    using Tag = typename std::conditional<
-        std::is_same<TDst, bool>::value,
-        BooleanTag,
-        typename std::conditional<
-            std::is_arithmetic<TDst>::value || std::is_enum<TDst>::value,
-            NumericTag,
-            typename std::conditional<
-                std::is_pointer<TDst>::value,
-                PointerTag,
-                typename std::conditional<
-                    std::is_class<TDst>::value,
-                    ClassTag,
-                    typename std::conditional<
-                        std::rank<TDst>::value == 1,
-                        Array1dTag,
-                        typename std::conditional<
-                            std::rank<TDst>::value == 2,
-                            Array2dTag,
-                            void
-                        >::type
-                    >::type
-                >::type
-            >::type
-        >::type
-    >::type;
-
-    static_assert(
-        !std::is_same<Tag, void>::value,
-        "Unsupported type.");
-
-    read<TSrc>(
-        dst_value,
-        Tag());
+       using Tag = typename std::conditional <
+               std::is_same<TDst, bool>::value,
+               BooleanTag,
+               typename std::conditional<
+                       std::is_arithmetic<TDst>::value || 
std::is_enum<TDst>::value,
+                       NumericTag,
+                       typename std::conditional<
+                               std::is_pointer<TDst>::value,
+                               PointerTag,
+                               typename std::conditional<
+                                       std::is_class<TDst>::value,
+                                       ClassTag,
+                                       typename std::conditional<
+                                               std::rank<TDst>::value == 1,
+                                               Array1dTag,
+                                               typename std::conditional<
+                                                       std::rank<TDst>::value 
== 2,
+                                                       Array2dTag,
+                                                       void
+                                               >::type
+                                       >::type
+                               >::type
+                       >::type
+               >::type
+       > ::type;
+
+       static_assert(
+               !std::is_same<Tag, void>::value,
+               "Unsupported type.");
+
+       read<TSrc>(
+               dst_value,
+               Tag());
 }
 
 template<typename TSrc, typename TDst>
 void ISavedGame::read(
-    TDst& dst_value,
-    BooleanTag)
+       TDst& dst_value,
+       BooleanTag)
 {
-    constexpr auto src_size = static_cast<int>(sizeof(TSrc));
+       constexpr auto src_size = static_cast<int>(sizeof(TSrc));
 
-    TSrc src_value;
+       TSrc src_value;
 
-    raw_read(
-        &src_value,
-        static_cast<int>(sizeof(TSrc)));
+       raw_read(
+               &src_value,
+               static_cast<int>(sizeof(TSrc)));
 
-    // FIXME Byte order
-    //
+       // FIXME Byte order
+       //
 
-    dst_value = (src_value != 0);
+       dst_value = (src_value != 0);
 }
 
 template<typename TSrc, typename TDst>
 void ISavedGame::read(
-    TDst& dst_value,
-    NumericTag)
+       TDst& dst_value,
+       NumericTag)
 {
-    constexpr auto src_size = static_cast<int>(sizeof(TSrc));
+       constexpr auto src_size = static_cast<int>(sizeof(TSrc));
 
-    TSrc src_value;
+       TSrc src_value;
 
-    raw_read(
-        &src_value,
-        src_size);
+       raw_read(
+               &src_value,
+               src_size);
 
-    // FIXME Byte order
-    //
+       // FIXME Byte order
+       //
 
-    dst_value = static_cast<TDst>(src_value);
+       dst_value = static_cast<TDst>(src_value);
 }
 
 template<typename TSrc, typename TDst>
 void ISavedGame::read(
-    TDst*& dst_value,
-    PointerTag)
+       TDst*& dst_value,
+       PointerTag)
 {
-    static_assert(
-        std::is_arithmetic<TSrc>::value &&
-            !std::is_same<TSrc, bool>::value,
-        "Unsupported types.");
+       static_assert(
+               std::is_arithmetic<TSrc>::value &&
+                       !std::is_same<TSrc, bool>::value,
+               "Unsupported types.");
 
-    using DstNumeric = typename std::conditional<
-        std::is_signed<TSrc>::value,
-        std::intptr_t,
-        std::uintptr_t
-    >::type;
+       using DstNumeric = typename std::conditional<
+               std::is_signed<TSrc>::value,
+               std::intptr_t,
+               std::uintptr_t
+       >::type;
 
-    auto dst_number = DstNumeric();
+       auto dst_number = DstNumeric();
 
-    read<TSrc>(
-        dst_number,
-        NumericTag());
+       read<TSrc>(
+               dst_number,
+               NumericTag());
 
-    dst_value = reinterpret_cast<TDst*>(dst_number);
+       dst_value = reinterpret_cast<TDst*>(dst_number);
 }
 
 template<typename TSrc, typename TDst>
 void ISavedGame::read(
-    TDst& dst_value,
-    ClassTag)
+       TDst& dst_value,
+       ClassTag)
 {
-    static_assert(
-        std::is_same<TSrc, void>::value,
-        "Unsupported types.");
+       static_assert(
+               std::is_same<TSrc, void>::value,
+               "Unsupported types.");
 
-    dst_value.sg_import(
-        this);
+       dst_value.sg_import(
+               this);
 }
 
 template<typename TSrc, typename TDst, int TCount>
 void ISavedGame::read(
-    TDst (&dst_values)[TCount],
-    Array1dTag)
+       TDst(&dst_values)[TCount],
+       Array1dTag)
 {
-    read<TSrc>(
-        &dst_values[0],
-        TCount);
+       read<TSrc>(
+               &dst_values[0],
+               TCount);
 }
 
 template<typename TSrc, typename TDst, int TCount1, int TCount2>
 void ISavedGame::read(
-    TDst(&dst_values)[TCount1][TCount2],
-    Array2dTag)
+       TDst(&dst_values)[TCount1][TCount2],
+       Array2dTag)
 {
-    read<TSrc>(
-        &dst_values[0][0],
-        TCount1 * TCount2);
+       read<TSrc>(
+               &dst_values[0][0],
+               TCount1 * TCount2);
 }
 
 // read
@@ -273,27 +274,27 @@ void ISavedGame::read(
 
 template<typename TSrc, typename TDst>
 bool ISavedGame::try_read(
-    TDst& dst_value)
+       TDst& dst_value)
 {
-    ScopeGuard scope_guard(
-        [this]()
-        {
-            this->allow_read_overflow(
-                true);
-        },
+       ScopeGuard scope_guard(
+               [this]()
+               {
+                       this->allow_read_overflow(
+                               true);
+               },
 
-        [this]()
-        {
-            this->allow_read_overflow(
-                false);
-        }
-    );
+               [this]()
+               {
+                       this->allow_read_overflow(
+                               false);
+               }
+       );
 
 
-    read<TSrc>(
-        dst_value);
+       read<TSrc>(
+               dst_value);
 
-    return is_all_data_read();
+       return is_all_data_read();
 }
 
 // try_read
@@ -305,103 +306,103 @@ bool ISavedGame::try_read(
 
 template<typename TSrc, typename TDst>
 void ISavedGame::read(
-    TDst* dst_values,
-    int dst_count)
+       TDst* dst_values,
+       int dst_count)
 {
-    static_assert(
-        (std::is_arithmetic<TDst>::value &&
-            !std::is_same<TDst, bool>::value &&
-            !std::is_enum<TDst>::value) ||
-            std::is_pointer<TDst>::value ||
-            std::is_class<TDst>::value,
-        "Unsupported types.");
-
-    using Src = typename std::conditional<
-        std::is_same<TSrc, void>::value,
-        TDst,
-        TSrc
-    >::type;
-
-    constexpr auto is_src_pure_numeric =
-        std::is_arithmetic<Src>::value &&
-            (!std::is_same<Src, bool>::value) &&
-            (!std::is_enum<Src>::value);
-
-    constexpr auto is_dst_pure_numeric =
-        std::is_arithmetic<TDst>::value &&
-            (!std::is_same<TDst, bool>::value) &&
-            (!std::is_enum<TDst>::value);
-
-    constexpr auto is_src_float_point =
-        std::is_floating_point<Src>::value;
-
-    constexpr auto is_dst_float_point =
-        std::is_floating_point<TDst>::value;
-
-    constexpr auto has_same_size =
-        (sizeof(Src) == sizeof(TDst));
-
-    constexpr auto use_inplace =
-        is_src_pure_numeric &&
-        is_dst_pure_numeric &&
-        ((!is_src_float_point && !is_dst_float_point) ||
-            (is_src_float_point && is_dst_float_point)) &&
-        has_same_size;
-
-    using Tag = typename std::conditional<
-        use_inplace,
-        InplaceTag,
-        CastTag
-    >::type;
-
-    read<TSrc>(
-        dst_values,
-        dst_count,
-        Tag());
+       static_assert(
+               (std::is_arithmetic<TDst>::value &&
+                       !std::is_same<TDst, bool>::value &&
+                       !std::is_enum<TDst>::value) ||
+                       std::is_pointer<TDst>::value ||
+                       std::is_class<TDst>::value,
+               "Unsupported types.");
+
+       using Src = typename std::conditional<
+               std::is_same<TSrc, void>::value,
+               TDst,
+               TSrc
+       >::type;
+
+       constexpr auto is_src_pure_numeric =
+               std::is_arithmetic<Src>::value &&
+               (!std::is_same<Src, bool>::value) &&
+               (!std::is_enum<Src>::value);
+
+       constexpr auto is_dst_pure_numeric =
+               std::is_arithmetic<TDst>::value &&
+               (!std::is_same<TDst, bool>::value) &&
+               (!std::is_enum<TDst>::value);
+
+       constexpr auto is_src_float_point =
+               std::is_floating_point<Src>::value;
+
+       constexpr auto is_dst_float_point =
+               std::is_floating_point<TDst>::value;
+
+       constexpr auto has_same_size =
+               (sizeof(Src) == sizeof(TDst));
+
+       constexpr auto use_inplace =
+               is_src_pure_numeric &&
+               is_dst_pure_numeric &&
+               ((!is_src_float_point && !is_dst_float_point) ||
+                       (is_src_float_point && is_dst_float_point)) &&
+               has_same_size;
+
+       using Tag = typename std::conditional<
+               use_inplace,
+               InplaceTag,
+               CastTag
+       >::type;
+
+       read<TSrc>(
+               dst_values,
+               dst_count,
+               Tag());
 }
 
 template<typename TSrc, typename TDst>
 void ISavedGame::read(
-    TDst* dst_values,
-    int dst_count,
-    InplaceTag)
+       TDst* dst_values,
+       int dst_count,
+       InplaceTag)
 {
-    const auto dst_size = dst_count * static_cast<int>(sizeof(TDst));
+       const auto dst_size = dst_count * static_cast<int>(sizeof(TDst));
 
-    raw_read(
-        dst_values,
-        dst_size);
+       raw_read(
+               dst_values,
+               dst_size);
 
-    // FIXME Byte order
-    //
+       // FIXME Byte order
+       //
 }
 
 template<typename TSrc, typename TDst>
 void ISavedGame::read(
-    TDst* dst_values,
-    int dst_count,
-    CastTag)
+       TDst* dst_values,
+       int dst_count,
+       CastTag)
 {
-    using Tag = typename std::conditional<
-        std::is_arithmetic<TDst>::value,
-        NumericTag,
-        typename std::conditional<
-            std::is_pointer<TDst>::value,
-            PointerTag,
-            typename std::conditional<
-                std::is_class<TDst>::value,
-                ClassTag,
-                void
-            >::type
-        >::type
-    >::type;
-
-    for (int i = 0; i < dst_count; ++i)
-    {
-        read<TSrc>(
-            dst_values[i],
-            Tag());
-    }
+       using Tag = typename std::conditional<
+               std::is_arithmetic<TDst>::value,
+               NumericTag,
+               typename std::conditional<
+                       std::is_pointer<TDst>::value,
+                       PointerTag,
+                       typename std::conditional<
+                               std::is_class<TDst>::value,
+                               ClassTag,
+                               void
+                       >::type
+               >::type
+       >::type;
+
+       for (int i = 0; i < dst_count; ++i)
+       {
+               read<TSrc>(
+                       dst_values[i],
+                       Tag());
+       }
 }
 
 // read (C-array)
@@ -413,105 +414,105 @@ void ISavedGame::read(
 
 template<typename TDst, typename TSrc>
 void ISavedGame::write(
-    const TSrc& src_value)
+       const TSrc& src_value)
 {
-    using Tag = typename std::conditional<
-        std::is_arithmetic<TSrc>::value || std::is_enum<TSrc>::value,
-        NumericTag,
-        typename std::conditional<
-            std::is_pointer<TSrc>::value,
-            PointerTag,
-            typename std::conditional<
-                std::is_class<TSrc>::value,
-                ClassTag,
-                typename std::conditional<
-                    std::rank<TSrc>::value == 1,
-                    Array1dTag,
-                    typename std::conditional<
-                        std::rank<TSrc>::value == 2,
-                        Array2dTag,
-                        void
-                    >::type
-                >::type
-            >::type
-        >::type
-    >::type;
-
-    static_assert(
-        !std::is_same<Tag, void>::value,
-        "Unsupported type.");
-
-    write<TDst>(
-        src_value,
-        Tag());
+       using Tag = typename std::conditional<
+               std::is_arithmetic<TSrc>::value || std::is_enum<TSrc>::value,
+               NumericTag,
+               typename std::conditional<
+                       std::is_pointer<TSrc>::value,
+                       PointerTag,
+                       typename std::conditional<
+                               std::is_class<TSrc>::value,
+                               ClassTag,
+                               typename std::conditional<
+                                       std::rank<TSrc>::value == 1,
+                                       Array1dTag,
+                                       typename std::conditional<
+                                               std::rank<TSrc>::value == 2,
+                                               Array2dTag,
+                                               void
+                                       >::type
+                               >::type
+                       >::type
+               >::type
+       >::type;
+
+       static_assert(
+               !std::is_same<Tag, void>::value,
+               "Unsupported type.");
+
+       write<TDst>(
+               src_value,
+               Tag());
 }
 
 template<typename TDst, typename TSrc>
 void ISavedGame::write(
-    const TSrc& src_value,
-    NumericTag)
+       const TSrc& src_value,
+       NumericTag)
 {
-    constexpr auto dst_size = static_cast<int>(sizeof(TDst));
+       constexpr auto dst_size = static_cast<int>(sizeof(TDst));
 
-    auto dst_value = static_cast<TDst>(src_value);
+       auto dst_value = static_cast<TDst>(src_value);
 
-    // FIXME Byte order
-    //
+       // FIXME Byte order
+       //
 
-    raw_write(
-        &dst_value,
-        dst_size);
+       raw_write(
+               &dst_value,
+               dst_size);
 }
 
 template<typename TDst, typename TSrc>
 void ISavedGame::write(
-    const TSrc* src_value,
-    PointerTag)
+       const TSrc* src_value,
+       PointerTag)
 {
-    using DstNumeric = typename std::conditional<
-        std::is_signed<TSrc>::value,
-        std::intptr_t,
-        std::uintptr_t
-    >::type;
+       using DstNumeric = typename std::conditional<
+               std::is_signed<TSrc>::value,
+               std::intptr_t,
+               std::uintptr_t
+       >::type;
 
-    auto dst_number = reinterpret_cast<DstNumeric>(src_value);
+       auto dst_number = reinterpret_cast<DstNumeric>(src_value);
 
-    write<TDst>(
-        dst_number,
-        NumericTag());
+       write<TDst>(
+               dst_number,
+               NumericTag());
 }
 
 template<typename TDst, typename TSrc>
 void ISavedGame::write(
-    const TSrc& src_value,
-    ClassTag)
+       const TSrc& src_value,
+       ClassTag)
 {
-    static_assert(
-        std::is_same<TDst, void>::value,
-        "Unsupported types.");
+       static_assert(
+               std::is_same<TDst, void>::value,
+               "Unsupported types.");
 
-    src_value.sg_export(
-        this);
+       src_value.sg_export(
+               this);
 }
 
 template<typename TDst, typename TSrc, int TCount>
 void ISavedGame::write(
-    const TSrc (&src_values)[TCount],
-    Array1dTag)
+       const TSrc(&src_values)[TCount],
+       Array1dTag)
 {
-    write<TDst>(
-        &src_values[0],
-        TCount);
+       write<TDst>(
+               &src_values[0],
+               TCount);
 }
 
 template<typename TDst, typename TSrc, int TCount1, int TCount2>
 void ISavedGame::write(
-    const TSrc (&src_values)[TCount1][TCount2],
-    Array2dTag)
+       const TSrc(&src_values)[TCount1][TCount2],
+       Array2dTag)
 {
-    write<TDst>(
-        &src_values[0][0],
-        TCount1 * TCount2);
+       write<TDst>(
+               &src_values[0][0],
+               TCount1 * TCount2);
 }
 
 // write
@@ -523,102 +524,102 @@ void ISavedGame::write(
 
 template<typename TDst, typename TSrc>
 void ISavedGame::write(
-    const TSrc* src_values,
-    int src_count)
+       const TSrc* src_values,
+       int src_count)
 {
-    static_assert(
-        (std::is_arithmetic<TSrc>::value &&
-            !std::is_same<TSrc, bool>::value &&
-            !std::is_enum<TSrc>::value) ||
-            std::is_pointer<TSrc>::value ||
-            std::is_class<TSrc>::value,
-        "Unsupported types.");
-
-    using Dst = typename std::conditional<
-        std::is_same<TDst, void>::value,
-        TSrc,
-        TDst>::type;
-
-    constexpr auto is_src_pure_numeric =
-        std::is_arithmetic<TSrc>::value &&
-            (!std::is_same<TSrc, bool>::value) &&
-            (!std::is_enum<TSrc>::value);
-
-    constexpr auto is_dst_pure_numeric =
-        std::is_arithmetic<Dst>::value &&
-            (!std::is_same<Dst, bool>::value) &&
-            (!std::is_enum<Dst>::value);
-
-    constexpr auto is_src_float_point =
-        std::is_floating_point<TSrc>::value;
-
-    constexpr auto is_dst_float_point =
-        std::is_floating_point<Dst>::value;
-
-    constexpr auto has_same_size =
-        (sizeof(TSrc) == sizeof(Dst));
-
-    constexpr auto use_inplace =
-        is_src_pure_numeric &&
-        is_dst_pure_numeric &&
-        ((!is_src_float_point && !is_dst_float_point) ||
-            (is_src_float_point && is_dst_float_point)) &&
-        has_same_size;
-
-    using Tag = typename std::conditional<
-        use_inplace,
-        InplaceTag,
-        CastTag
-    >::type;
-
-    write<TDst>(
-        src_values,
-        src_count,
-        Tag());
+       static_assert(
+               (std::is_arithmetic<TSrc>::value &&
+                       !std::is_same<TSrc, bool>::value &&
+                       !std::is_enum<TSrc>::value) ||
+                       std::is_pointer<TSrc>::value ||
+                       std::is_class<TSrc>::value,
+               "Unsupported types.");
+
+       using Dst = typename std::conditional<
+               std::is_same<TDst, void>::value,
+               TSrc,
+               TDst>::type;
+
+       constexpr auto is_src_pure_numeric =
+               std::is_arithmetic<TSrc>::value &&
+               (!std::is_same<TSrc, bool>::value) &&
+               (!std::is_enum<TSrc>::value);
+
+       constexpr auto is_dst_pure_numeric =
+               std::is_arithmetic<Dst>::value &&
+               (!std::is_same<Dst, bool>::value) &&
+               (!std::is_enum<Dst>::value);
+
+       constexpr auto is_src_float_point =
+               std::is_floating_point<TSrc>::value;
+
+       constexpr auto is_dst_float_point =
+               std::is_floating_point<Dst>::value;
+
+       constexpr auto has_same_size =
+               (sizeof(TSrc) == sizeof(Dst));
+
+       constexpr auto use_inplace =
+               is_src_pure_numeric &&
+               is_dst_pure_numeric &&
+               ((!is_src_float_point && !is_dst_float_point) ||
+               (is_src_float_point && is_dst_float_point)) &&
+               has_same_size;
+
+       using Tag = typename std::conditional<
+               use_inplace,
+               InplaceTag,
+               CastTag
+       >::type;
+
+       write<TDst>(
+               src_values,
+               src_count,
+               Tag());
 }
 
 template<typename TDst, typename TSrc>
 void ISavedGame::write(
-    const TSrc* src_values,
-    int src_count,
-    InplaceTag)
+       const TSrc* src_values,
+       int src_count,
+       InplaceTag)
 {
-    const auto src_size = src_count * static_cast<int>(sizeof(TSrc));
+       const auto src_size = src_count * static_cast<int>(sizeof(TSrc));
 
-    raw_write(
-        src_values,
-        src_size);
+       raw_write(
+               src_values,
+               src_size);
 
-    // FIXME Byte order
-    //
+       // FIXME Byte order
+       //
 }
 
 template<typename TDst, typename TSrc>
 void ISavedGame::write(
-    const TSrc* src_values,
-    int src_count,
-    CastTag)
+       const TSrc* src_values,
+       int src_count,
+       CastTag)
 {
-    using Tag = typename std::conditional<
-        std::is_arithmetic<TSrc>::value,
-        NumericTag,
-        typename std::conditional<
-            std::is_pointer<TSrc>::value,
-            PointerTag,
-            typename std::conditional<
-                std::is_class<TSrc>::value,
-                ClassTag,
-                void
-            >::type
-        >::type
-    >::type;
-
-    for (int i = 0; i < src_count; ++i)
-    {
-        write<TDst>(
-            src_values[i],
-            Tag());
-    }
+       using Tag = typename std::conditional<
+               std::is_arithmetic<TSrc>::value,
+               NumericTag,
+               typename std::conditional<
+                       std::is_pointer<TSrc>::value,
+                       PointerTag,
+                       typename std::conditional<
+                               std::is_class<TSrc>::value,
+                               ClassTag,
+                               void
+                       >::type
+               >::type
+       >::type;
+
+       for (int i = 0; i < src_count; ++i)
+       {
+               write<TDst>(
+                       src_values[i],
+                       Tag());
+       }
 }
 
 // write (C-array)
diff --git a/shared/qcommon/ojk_i_saved_game_fwd.h 
b/shared/qcommon/ojk_i_saved_game_fwd.h
index 91a7e61..7a3bb59 100644
--- a/shared/qcommon/ojk_i_saved_game_fwd.h
+++ b/shared/qcommon/ojk_i_saved_game_fwd.h
@@ -19,245 +19,269 @@ namespace ojk
 class ISavedGame
 {
 public:
-    using ChunkId = uint32_t;
+       using ChunkId = uint32_t;
 
 
-    ISavedGame();
+       ISavedGame();
 
-    ISavedGame(
-        const ISavedGame& that) = delete;
+       ISavedGame(
+               const ISavedGame& that) = delete;
 
-    ISavedGame& operator=(
-        const ISavedGame& that) = delete;
+       ISavedGame& operator=(
+               const ISavedGame& that) = delete;
 
-    virtual ~ISavedGame();
+       virtual ~ISavedGame();
 
 
-    // Returns true if the saved game opened for reading.
-    virtual bool is_readable() const = 0;
+       // Returns true if the saved game opened for reading.
+       virtual bool is_readable() const = 0;
 
-    // Returns true if the saved game opened for writing.
-    virtual bool is_writable() const = 0;
+       // Returns true if the saved game opened for writing.
+       virtual bool is_writable() const = 0;
 
 
-    // Reads a chunk from the file into the internal buffer.
-    virtual void read_chunk(
-        const ChunkId chunk_id) = 0;
+       // Reads a chunk from the file into the internal buffer.
+       virtual void read_chunk(
+               const ChunkId chunk_id) = 0;
 
-    // Reads a value or an array of values from the file via
-    // the internal buffer.
-    template<typename TSrc = void, typename TDst = void>
-    void read_chunk(
-        const ChunkId chunk_id,
-        TDst& dst_value);
+       // Reads a value or an array of values from the file via
+       // the internal buffer.
+       template<typename TSrc = void, typename TDst = void>
+       void read_chunk(
+               const ChunkId chunk_id,
+               TDst& dst_value);
 
-    // Reads an array of values with specified count from
-    // the file via the internal buffer.
-    template<typename TSrc = void, typename TDst = void>
-    void read_chunk(
-        const ChunkId chunk_id,
-        TDst* dst_values,
-        int dst_count);
+       // Reads an array of values with specified count from
+       // the file via the internal buffer.
+       template<typename TSrc = void, typename TDst = void>
+       void read_chunk(
+               const ChunkId chunk_id,
+               TDst* dst_values,
+               int dst_count);
 
-    // Returns true if all data read from the internal buffer.
-    virtual bool is_all_data_read() const = 0;
+       // Returns true if all data read from the internal buffer.
+       virtual bool is_all_data_read() const = 0;
 
-    // Throws an exception if all data not read.
-    virtual void ensure_all_data_read() const = 0;
+       // Throws an exception if all data not read.
+       virtual void ensure_all_data_read() const = 0;
 
 
-    // Writes a chunk into the file from the internal buffer.
-    virtual void write_chunk(
-        const ChunkId chunk_id) = 0;
+       // Writes a chunk into the file from the internal buffer.
+       virtual void write_chunk(
+               const ChunkId chunk_id) = 0;
 
-    // Writes a data-chunk into the file from the internal buffer
-    // prepended with a size-chunk that holds a size of the data-chunk.
-    template<typename TSize>
-    void write_chunk_and_size(
-        const ChunkId size_chunk_id,
-        const ChunkId data_chunk_id);
+       // Writes a data-chunk into the file from the internal buffer
+       // prepended with a size-chunk that holds a size of the data-chunk.
+       template<typename TSize>
+       void write_chunk_and_size(
+               const ChunkId size_chunk_id,
+               const ChunkId data_chunk_id);
 
-    // Writes a value or an array of values into the file via
-    // the internal buffer.
-    template<typename TDst = void, typename TSrc = void>
-    void write_chunk(
-        const ChunkId chunk_id,
-        const TSrc& src_value);
+       // Writes a value or an array of values into the file via
+       // the internal buffer.
+       template<typename TDst = void, typename TSrc = void>
+       void write_chunk(
+               const ChunkId chunk_id,
+               const TSrc& src_value);
 
-    // Writes an array of values with specified count into
-    // the file via the internal buffer.
-    template<typename TDst = void, typename TSrc = void>
-    void write_chunk(
-        const ChunkId chunk_id,
-        const TSrc* src_values,
-        int src_count);
+       // Writes an array of values with specified count into
+       // the file via the internal buffer.
+       template<typename TDst = void, typename TSrc = void>
+       void write_chunk(
+               const ChunkId chunk_id,
+               const TSrc* src_values,
+               int src_count);
 
 
-    // Reads a raw data from the internal buffer.
-    virtual void raw_read(
-        void* dst_data,
-        int dst_size) = 0;
+       // Reads a raw data from the internal buffer.
+       virtual void raw_read(
+               void* dst_data,
+               int dst_size) = 0;
 
-    // Reads a value or array of values from the internal buffer.
-    template<typename TSrc = void, typename TDst = void>
-    void read(
-        TDst& dst_value);
+       // Reads a value or array of values from the internal buffer.
+       template<typename TSrc = void, typename TDst = void>
+       void read(
+               TDst& dst_value);
 
-    // Reads an array of values with specificed count from the internal buffer.
-    template<typename TSrc = void, typename TDst = void>
-    void read(
-        TDst* dst_values,
-        int dst_count);
+       // Reads an array of values with specificed count from the internal 
buffer.
+       template<typename TSrc = void, typename TDst = void>
+       void read(
+               TDst* dst_values,
+               int dst_count);
 
 
-    // Tries to read a value or array of values from the internal buffer.
-    // Returns true on success or false otherwise.
-    template<typename TSrc = void, typename TDst = void>
-    bool try_read(
-        TDst& dst_value);
+       // Tries to read a value or array of values from the internal buffer.
+       // Returns true on success or false otherwise.
+       template<typename TSrc = void, typename TDst = void>
+       bool try_read(
+               TDst& dst_value);
 
 
-    // Writes a raw data into the internal buffer.
-    virtual void raw_write(
-        const void* src_data,
-        int src_size) = 0;
+       // Writes a raw data into the internal buffer.
+       virtual void raw_write(
+               const void* src_data,
+               int src_size) = 0;
 
-    // Writes a value or array of values into the internal buffer.
-    template<typename TDst = void, typename TSrc = void>
-    void write(
-        const TSrc& src_value);
+       // Writes a value or array of values into the internal buffer.
+       template<typename TDst = void, typename TSrc = void>
+       void write(
+               const TSrc& src_value);
 
-    // Writes an array of values with specificed count into the internal 
buffer.
-    template<typename TDst = void, typename TSrc = void>
-    void write(
-        const TSrc* src_values,
-        int src_count);
+       // Writes an array of values with specificed count into the internal 
buffer.
+       template<typename TDst = void, typename TSrc = void>
+       void write(
+               const TSrc* src_values,
+               int src_count);
 
 
-    // Increments buffer's offset by the specified non-negative count.
-    virtual void skip(
-        int count) = 0;
+       // Increments buffer's offset by the specified non-negative count.
+       virtual void skip(
+               int count) = 0;
 
 
-    // Stores current I/O buffer and it's position.
-    virtual void save_buffer() = 0;
+       // Stores current I/O buffer and it's position.
+       virtual void save_buffer() = 0;
 
-    // Restores saved I/O buffer and it's position.
-    virtual void load_buffer() = 0;
+       // Restores saved I/O buffer and it's position.
+       virtual void load_buffer() = 0;
 
-    // Returns a pointer to data in the I/O buffer.
-    virtual const void* get_buffer_data() const = 0;
+       // Returns a pointer to data in the I/O buffer.
+       virtual const void* get_buffer_data() const = 0;
 
-    // Returns a current size of the I/O buffer.
-    virtual int get_buffer_size() const = 0;
+       // Returns a current size of the I/O buffer.
+       virtual int get_buffer_size() const = 0;
 
 
-    // Clears buffer and resets it's offset to the beginning.
-    virtual void reset_buffer() = 0;
+       // Clears buffer and resets it's offset to the beginning.
+       virtual void reset_buffer() = 0;
 
-    // Resets buffer offset to the beginning.
-    virtual void reset_buffer_offset() = 0;
+       // Resets buffer offset to the beginning.
+       virtual void reset_buffer_offset() = 0;
 
 
 protected:
-    // Tags for dispatching.
-    class BooleanTag { public: };
-    class NumericTag { public: };
-    class PointerTag { public: };
-    class ClassTag { public: };
-    class Array1dTag { public: };
-    class Array2dTag { public: };
-    class InplaceTag { public: };
-    class CastTag { public: };
-
-
-    // If true won't throw an exception when buffer offset is beyond it's size.
-    // Although, no data will be read beyond the buffer.
-    virtual void allow_read_overflow(
-        bool value) = 0;
-
-
-    template<typename TSrc, typename TDst>
-    void read(
-        TDst& dst_value,
-        BooleanTag);
-
-    template<typename TSrc, typename TDst>
-    void read(
-        TDst& dst_value,
-        NumericTag);
-
-    template<typename TSrc, typename TDst>
-    void read(
-        TDst*& dst_value,
-        PointerTag);
-
-    template<typename TSrc, typename TDst>
-    void read(
-        TDst& dst_value,
-        ClassTag);
-
-    template<typename TSrc, typename TDst, int TCount>
-    void read(
-        TDst (&dst_values)[TCount],
-        Array1dTag);
-
-    template<typename TSrc, typename TDst, int TCount1, int TCount2>
-    void read(
-        TDst (&dst_values)[TCount1][TCount2],
-        Array2dTag);
-
-
-    template<typename TSrc, typename TDst>
-    void read(
-        TDst* dst_values,
-        int dst_count,
-        InplaceTag);
-
-    template<typename TSrc, typename TDst>
-    void read(
-        TDst* dst_values,
-        int dst_count,
-        CastTag);
-
-
-    template<typename TDst, typename TSrc>
-    void write(
-        const TSrc& src_value,
-        NumericTag);
-
-    template<typename TDst, typename TSrc>
-    void write(
-        const TSrc* src_value,
-        PointerTag);
-
-    template<typename TDst, typename TSrc>
-    void write(
-        const TSrc& src_value,
-        ClassTag);
-
-    template<typename TDst, typename TSrc, int TCount>
-    void write(
-        const TSrc (&src_values)[TCount],
-        Array1dTag);
-
-    template<typename TDst, typename TSrc, int TCount1, int TCount2>
-    void write(
-        const TSrc (&src_values)[TCount1][TCount2],
-        Array2dTag);
-
-
-    template<typename TDst, typename TSrc>
-    void write(
-        const TSrc* src_values,
-        int src_count,
-        InplaceTag);
-
-    template<typename TDst, typename TSrc>
-    void write(
-        const TSrc* src_values,
-        int src_count,
-        CastTag);
+       // Tags for dispatching.
+       class BooleanTag
+       {
+       public:
+       };
+       class NumericTag
+       {
+       public:
+       };
+       class PointerTag
+       {
+       public:
+       };
+       class ClassTag
+       {
+       public:
+       };
+       class Array1dTag
+       {
+       public:
+       };
+       class Array2dTag
+       {
+       public:
+       };
+       class InplaceTag
+       {
+       public:
+       };
+       class CastTag
+       {
+       public:
+       };
+
+
+       // If true won't throw an exception when buffer offset is beyond it's 
size.
+       // Although, no data will be read beyond the buffer.
+       virtual void allow_read_overflow(
+               bool value) = 0;
+
+
+       template<typename TSrc, typename TDst>
+       void read(
+               TDst& dst_value,
+               BooleanTag);
+
+       template<typename TSrc, typename TDst>
+       void read(
+               TDst& dst_value,
+               NumericTag);
+
+       template<typename TSrc, typename TDst>
+       void read(
+               TDst*& dst_value,
+               PointerTag);
+
+       template<typename TSrc, typename TDst>
+       void read(
+               TDst& dst_value,
+               ClassTag);
+
+       template<typename TSrc, typename TDst, int TCount>
+       void read(
+               TDst(&dst_values)[TCount],
+               Array1dTag);
+
+       template<typename TSrc, typename TDst, int TCount1, int TCount2>
+       void read(
+               TDst(&dst_values)[TCount1][TCount2],
+               Array2dTag);
+
+
+       template<typename TSrc, typename TDst>
+       void read(
+               TDst* dst_values,
+               int dst_count,
+               InplaceTag);
+
+       template<typename TSrc, typename TDst>
+       void read(
+               TDst* dst_values,
+               int dst_count,
+               CastTag);
+
+
+       template<typename TDst, typename TSrc>
+       void write(
+               const TSrc& src_value,
+               NumericTag);
+
+       template<typename TDst, typename TSrc>
+       void write(
+               const TSrc* src_value,
+               PointerTag);
+
+       template<typename TDst, typename TSrc>
+       void write(
+               const TSrc& src_value,
+               ClassTag);
+
+       template<typename TDst, typename TSrc, int TCount>
+       void write(
+               const TSrc(&src_values)[TCount],
+               Array1dTag);
+
+       template<typename TDst, typename TSrc, int TCount1, int TCount2>
+       void write(
+               const TSrc(&src_values)[TCount1][TCount2],
+               Array2dTag);
+
+
+       template<typename TDst, typename TSrc>
+       void write(
+               const TSrc* src_values,
+               int src_count,
+               InplaceTag);
+
+       template<typename TDst, typename TSrc>
+       void write(
+               const TSrc* src_values,
+               int src_count,
+               CastTag);
 }; // ISavedGame
 
 
diff --git a/shared/qcommon/ojk_saved_game.cpp 
b/shared/qcommon/ojk_saved_game.cpp
index d10cecc..c4a270f 100644
--- a/shared/qcommon/ojk_saved_game.cpp
+++ b/shared/qcommon/ojk_saved_game.cpp
@@ -10,846 +10,857 @@ namespace ojk
 
 
 SavedGame::SavedGame() :
-        file_handle_(),
-        io_buffer_(),
-        saved_io_buffer_(),
-        io_buffer_offset_(),
-        saved_io_buffer_offset_(),
-        rle_buffer_(),
-        is_readable_(),
-        is_writable_(),
-        is_write_failed_(),
-        is_read_overflow_allowed_()
+               file_handle_(),
+               io_buffer_(),
+               saved_io_buffer_(),
+               io_buffer_offset_(),
+               saved_io_buffer_offset_(),
+               rle_buffer_(),
+               is_readable_(),
+               is_writable_(),
+               is_write_failed_(),
+               is_read_overflow_allowed_()
 {
 }
 
 SavedGame::~SavedGame()
 {
-    close();
+       close();
 }
 
 bool SavedGame::open(
-    const std::string& base_file_name)
+       const std::string& base_file_name)
 {
-    close();
+       close();
 
 
-    const auto&& file_path = generate_path(
-        base_file_name);
+       const auto&& file_path = generate_path(
+               base_file_name);
 
-    auto is_succeed = true;
+       auto is_succeed = true;
 
-    if (is_succeed)
-    {
-        ::FS_FOpenFileRead(
-            file_path.c_str(),
-            &file_handle_,
-            qtrue);
+       static_cast<void>(::FS_FOpenFileRead(
+               file_path.c_str(),
+               &file_handle_,
+               true));
 
-        if (file_handle_ == 0)
-        {
-            is_succeed = false;
+       if (file_handle_ == 0)
+       {
+               is_succeed = false;
 
-            const auto&& error_message =
-                S_COLOR_RED "Failed to open a saved game file: \"" +
-                    file_path + "\".";
+               const auto&& error_message =
+                       S_COLOR_RED "Failed to open a saved game file: \"" +
+                       file_path + "\".";
 
-            ::Com_DPrintf(
-                "%s\n",
-                error_message.c_str());
-        }
-    }
+               ::Com_DPrintf(
+                       "%s\n",
+                       error_message.c_str());
+       }
 
-    if (is_succeed)
-    {
-        is_readable_ = true;
-    }
+       if (is_succeed)
+       {
+               is_readable_ = true;
+       }
 
-    auto sg_version = -1;
+       auto sg_version = -1;
 
-    if (is_succeed)
-    {
-        static_cast<void>(read_chunk<int32_t>(
-            INT_ID('_', 'V', 'E', 'R'),
-            sg_version));
+       if (is_succeed)
+       {
+               static_cast<void>(read_chunk<int32_t>(
+                       INT_ID('_', 'V', 'E', 'R'),
+                       sg_version));
 
-        if (sg_version != iSAVEGAME_VERSION)
-        {
-            is_succeed = false;
+               if (sg_version != iSAVEGAME_VERSION)
+               {
+                       is_succeed = false;
 
-            ::Com_Printf(
-                S_COLOR_RED "File \"%s\" has version # %d (expecting %d)\n",
-                base_file_name.c_str(),
-                sg_version,
-                iSAVEGAME_VERSION);
-        }
-    }
+                       ::Com_Printf(
+                               S_COLOR_RED "File \"%s\" has version # %d 
(expecting %d)\n",
+                               base_file_name.c_str(),
+                               sg_version,
+                               iSAVEGAME_VERSION);
+               }
+       }
 
-    if (!is_succeed)
-    {
-        close();
-    }
+       if (!is_succeed)
+       {
+               close();
+       }
 
-    return is_succeed;
+       return is_succeed;
 }
 
 bool SavedGame::create(
-    const std::string& base_file_name)
+       const std::string& base_file_name)
 {
-    close();
+       close();
 
 
-    remove(
-        base_file_name);
+       remove(
+               base_file_name);
 
-    const auto&& file_path = generate_path(
-        base_file_name);
+       const auto&& file_path = generate_path(
+               base_file_name);
 
-    file_handle_ = ::FS_FOpenFileWrite(
-        file_path.c_str());
+       file_handle_ = ::FS_FOpenFileWrite(
+               file_path.c_str());
 
-    if (file_handle_ == 0)
-    {
-        const auto&& error_message =
-            S_COLOR_RED "Failed to create a saved game file: \"" +
-                file_path + "\".";
+       if (file_handle_ == 0)
+       {
+               const auto&& error_message =
+                       S_COLOR_RED "Failed to create a saved game file: \"" +
+                       file_path + "\".";
 
-        ::Com_Printf(
-            "%s\n",
-            error_message.c_str());
+               ::Com_Printf(
+                       "%s\n",
+                       error_message.c_str());
 
-        return false;
-    }
+               return false;
+       }
 
 
-    is_writable_ = true;
+       is_writable_ = true;
 
-    const auto sg_version = iSAVEGAME_VERSION;
+       const auto sg_version = iSAVEGAME_VERSION;
 
-    write_chunk<int32_t>(
-        INT_ID('_', 'V', 'E', 'R'),
-        sg_version);
+       write_chunk<int32_t>(
+               INT_ID('_', 'V', 'E', 'R'),
+               sg_version);
 
-    return true;
+       return true;
 }
 
 void SavedGame::close()
 {
-    if (file_handle_ != 0)
-    {
-        ::FS_FCloseFile(file_handle_);
-        file_handle_ = 0;
-    }
+       if (file_handle_ != 0)
+       {
+               ::FS_FCloseFile(file_handle_);
+               file_handle_ = 0;
+       }
 
-    io_buffer_.clear();
-    io_buffer_offset_ = 0;
+       io_buffer_.clear();
+       io_buffer_offset_ = 0;
 
-    is_readable_ = false;
-    is_writable_ = false;
-    is_write_failed_ = false;
+       is_readable_ = false;
+       is_writable_ = false;
+       is_write_failed_ = false;
 }
 
 bool SavedGame::is_readable() const
 {
-    return is_readable_;
+       return is_readable_;
 }
 
 bool SavedGame::is_writable() const
 {
-    return is_writable_;
+       return is_writable_;
 }
 
 void SavedGame::read_chunk(
-    const SavedGame::ChunkId chunk_id)
+       const SavedGame::ChunkId chunk_id)
 {
-    io_buffer_offset_ = 0;
+       io_buffer_offset_ = 0;
 
-    const auto&& chunk_id_string = get_chunk_id_string(
-        chunk_id);
+       const auto&& chunk_id_string = get_chunk_id_string(
+               chunk_id);
 
-    ::Com_DPrintf(
-        "Attempting read of chunk %s\n",
-        chunk_id_string.c_str());
+       ::Com_DPrintf(
+               "Attempting read of chunk %s\n",
+               chunk_id_string.c_str());
 
-    uint32_t ulLoadedChid = 0;
-    uint32_t uiLoadedLength = 0;
+       uint32_t ulLoadedChid = 0;
+       uint32_t uiLoadedLength = 0;
 
-    auto uiLoaded = ::FS_Read(
-        &ulLoadedChid,
-        static_cast<int>(sizeof(ulLoadedChid)),
-        file_handle_);
+       auto uiLoaded = ::FS_Read(
+               &ulLoadedChid,
+               static_cast<int>(sizeof(ulLoadedChid)),
+               file_handle_);
 
-    uiLoaded += ::FS_Read(
-        &uiLoadedLength,
-        static_cast<int>(sizeof(uiLoadedLength)),
-        file_handle_);
+       uiLoaded += ::FS_Read(
+               &uiLoadedLength,
+               static_cast<int>(sizeof(uiLoadedLength)),
+               file_handle_);
 
-    const auto bBlockIsCompressed = (static_cast<int32_t>(uiLoadedLength) < 0);
+       const auto bBlockIsCompressed = (static_cast<int32_t>(uiLoadedLength) < 
0);
 
-    if (bBlockIsCompressed)
-    {
-        uiLoadedLength = -static_cast<int32_t>(uiLoadedLength);
-    }
+       if (bBlockIsCompressed)
+       {
+               uiLoadedLength = -static_cast<int32_t>(uiLoadedLength);
+       }
 
-    // Make sure we are loading the correct chunk...
-    //
-    if (ulLoadedChid != chunk_id)
-    {
-        const auto&& loaded_chunk_id_string = get_chunk_id_string(
-            ulLoadedChid);
+       // Make sure we are loading the correct chunk...
+       //
+       if (ulLoadedChid != chunk_id)
+       {
+               const auto&& loaded_chunk_id_string = get_chunk_id_string(
+                       ulLoadedChid);
 
-        const auto&& error_message =
-            "Loaded chunk ID (" +
-            loaded_chunk_id_string +
-            ") does not match requested chunk ID (" +
-            chunk_id_string +
-            ").";
+               const auto&& error_message =
+                       "Loaded chunk ID (" +
+                       loaded_chunk_id_string +
+                       ") does not match requested chunk ID (" +
+                       chunk_id_string +
+                       ").";
 
-        throw_error(
-            error_message);
-    }
+               throw_error(
+                       error_message);
+       }
 
-    uint32_t uiLoadedCksum = 0;
+       uint32_t uiLoadedCksum = 0;
 
 #ifdef JK2_MODE
-    // Get checksum...
-    //
-    uiLoaded += ::FS_Read(
-        &uiLoadedCksum,
-        static_cast<int>(sizeof(uiLoadedCksum)),
-        file_handle_);
+       // Get checksum...
+       //
+       uiLoaded += ::FS_Read(
+               &uiLoadedCksum,
+               static_cast<int>(sizeof(uiLoadedCksum)),
+               file_handle_);
 #endif // JK2_MODE
 
-    // Load in data and magic number...
-    //
-    uint32_t uiCompressedLength = 0;
-
-    if (bBlockIsCompressed)
-    {
-        uiLoaded += ::FS_Read(
-            &uiCompressedLength,
-            static_cast<int>(sizeof(uiCompressedLength)),
-            file_handle_);
-
-        rle_buffer_.resize(
-            uiCompressedLength);
-
-        uiLoaded += ::FS_Read(
-            rle_buffer_.data(),
-            uiCompressedLength,
-            file_handle_);
-
-        io_buffer_.resize(
-            uiLoadedLength);
-
-        decompress(
-            rle_buffer_,
-            io_buffer_);
-    }
-    else
-    {
-        io_buffer_.resize(
-            uiLoadedLength);
-
-        uiLoaded += ::FS_Read(
-            io_buffer_.data(),
-            uiLoadedLength,
-            file_handle_);
-    }
+       // Load in data and magic number...
+       //
+       uint32_t uiCompressedLength = 0;
+
+       if (bBlockIsCompressed)
+       {
+               uiLoaded += ::FS_Read(
+                       &uiCompressedLength,
+                       static_cast<int>(sizeof(uiCompressedLength)),
+                       file_handle_);
+
+               rle_buffer_.resize(
+                       uiCompressedLength);
+
+               uiLoaded += ::FS_Read(
+                       rle_buffer_.data(),
+                       uiCompressedLength,
+                       file_handle_);
+
+               io_buffer_.resize(
+                       uiLoadedLength);
+
+               decompress(
+                       rle_buffer_,
+                       io_buffer_);
+       }
+       else
+       {
+               io_buffer_.resize(
+                       uiLoadedLength);
+
+               uiLoaded += ::FS_Read(
+                       io_buffer_.data(),
+                       uiLoadedLength,
+                       file_handle_);
+       }
 
 #ifdef JK2_MODE
-    uint32_t uiLoadedMagic = 0;
+       uint32_t uiLoadedMagic = 0;
 
-    uiLoaded += ::FS_Read(
-        &uiLoadedMagic,
-        static_cast<int>(sizeof(uiLoadedMagic)),
-        file_handle_);
+       uiLoaded += ::FS_Read(
+               &uiLoadedMagic,
+               static_cast<int>(sizeof(uiLoadedMagic)),
+               file_handle_);
 
-    if (uiLoadedMagic != get_jo_magic_value())
-    {
-        const auto&& error_message =
-            "Bad saved game magic for chunk " + chunk_id_string + ".";
+       if (uiLoadedMagic != get_jo_magic_value())
+       {
+               const auto&& error_message =
+                       "Bad saved game magic for chunk " + chunk_id_string + 
".";
 
-        throw_error(
-            error_message);
-    }
+               throw_error(
+                       error_message);
+       }
 #endif // JK2_MODE
 
 #ifndef JK2_MODE
-    // Get checksum...
-    //
-    uiLoaded += ::FS_Read(
-        &uiLoadedCksum,
-        static_cast<int>(sizeof(uiLoadedCksum)),
-        file_handle_);
+       // Get checksum...
+       //
+       uiLoaded += ::FS_Read(
+               &uiLoadedCksum,
+               static_cast<int>(sizeof(uiLoadedCksum)),
+               file_handle_);
 #endif // !JK2_MODE
 
-    // Make sure the checksums match...
-    //
-    const auto uiCksum = ::Com_BlockChecksum(
-        io_buffer_.data(),
-        static_cast<int>(io_buffer_.size()));
-
-    if (uiLoadedCksum != uiCksum)
-    {
-        const auto&& error_message =
-            "Failed checksum check for chunk " + chunk_id_string + ".";
-
-        throw_error(
-            error_message);
-    }
-
-    // Make sure we didn't encounter any read errors...
-    if (uiLoaded !=
-        sizeof(ulLoadedChid) +
-        sizeof(uiLoadedLength) +
-        sizeof(uiLoadedCksum) +
-        (bBlockIsCompressed ? sizeof(uiCompressedLength) : 0) +
-        (bBlockIsCompressed ? uiCompressedLength : io_buffer_.size()) +
+       // Make sure the checksums match...
+       //
+       const auto uiCksum = ::Com_BlockChecksum(
+               io_buffer_.data(),
+               static_cast<int>(io_buffer_.size()));
+
+       if (uiLoadedCksum != uiCksum)
+       {
+               const auto&& error_message =
+                       "Failed checksum check for chunk " + chunk_id_string + 
".";
+
+               throw_error(
+                       error_message);
+       }
+
+       // Make sure we didn't encounter any read errors...
+       if (uiLoaded !=
+               sizeof(ulLoadedChid) +
+               sizeof(uiLoadedLength) +
+               sizeof(uiLoadedCksum) +
+               (bBlockIsCompressed ? sizeof(uiCompressedLength) : 0) +
+               (bBlockIsCompressed ? uiCompressedLength : io_buffer_.size()) +
 #ifdef JK2_MODE
-        sizeof(uiLoadedMagic) +
+               sizeof(uiLoadedMagic) +
 #endif
-        0)
-    {
-        const auto&& error_message =
-            "Error during loading chunk " + chunk_id_string + ".";
+               0)
+       {
+               const auto&& error_message =
+                       "Error during loading chunk " + chunk_id_string + ".";
 
-        throw_error(
-            error_message);
-    }
+               throw_error(
+                       error_message);
+       }
 }
 
 bool SavedGame::is_all_data_read() const
 {
-    return io_buffer_.size() == io_buffer_offset_;
+       return io_buffer_.size() == io_buffer_offset_;
 }
 
 void SavedGame::ensure_all_data_read() const
 {
-    if (!is_all_data_read())
-    {
-        throw_error(
-            "Not all expected data read.");
-    }
+       if (!is_all_data_read())
+       {
+               throw_error(
+                       "Not all expected data read.");
+       }
 }
 
 void SavedGame::write_chunk(
-    const SavedGame::ChunkId chunk_id)
+       const SavedGame::ChunkId chunk_id)
 {
-    const auto&& chunk_id_string = get_chunk_id_string(
-        chunk_id);
+       const auto&& chunk_id_string = get_chunk_id_string(
+               chunk_id);
 
-    ::Com_DPrintf(
-        "Attempting write of chunk %s\n",
-        chunk_id_string.c_str());
+       ::Com_DPrintf(
+               "Attempting write of chunk %s\n",
+               chunk_id_string.c_str());
 
-    if (::sv_testsave->integer != 0)
-    {
-        return;
-    }
+       if (::sv_testsave->integer != 0)
+       {
+               return;
+       }
 
-    const auto src_size = static_cast<int>(io_buffer_.size());
+       const auto src_size = static_cast<int>(io_buffer_.size());
 
-    const auto uiCksum = Com_BlockChecksum(
-        io_buffer_.data(),
-        src_size);
+       const auto uiCksum = Com_BlockChecksum(
+               io_buffer_.data(),
+               src_size);
 
-    uint32_t uiSaved = ::FS_Write(
-        &chunk_id,
-        static_cast<int>(sizeof(chunk_id)),
-        file_handle_);
+       uint32_t uiSaved = ::FS_Write(
+               &chunk_id,
+               static_cast<int>(sizeof(chunk_id)),
+               file_handle_);
 
-#ifdef JK2_MODE
-    uiSaved += ::FS_Write(
-        &uiCksum,
-        static_cast<int>(sizeof(uiCksum)),
-        file_handle_);
-#endif // JK2_MODE
+#ifndef JK2_MODE
+       uiSaved += ::FS_Write(
+               &uiCksum,
+               static_cast<int>(sizeof(uiCksum)),
+               file_handle_);
+#endif // !JK2_MODE
 
-    auto iCompressedLength = -1;
+       auto iCompressedLength = -1;
 
-    if (::sv_compress_saved_games->integer != 0)
-    {
-        compress(
-            io_buffer_,
-            rle_buffer_);
+       if (::sv_compress_saved_games->integer != 0)
+       {
+               compress(
+                       io_buffer_,
+                       rle_buffer_);
 
-        if (rle_buffer_.size() < io_buffer_.size())
-        {
-            iCompressedLength = static_cast<int>(rle_buffer_.size());
-        }
-    }
+               if (rle_buffer_.size() < io_buffer_.size())
+               {
+                       iCompressedLength = 
static_cast<int>(rle_buffer_.size());
+               }
+       }
 
 #ifdef JK2_MODE
-    const auto uiMagic = get_jo_magic_value();
+       const auto uiMagic = get_jo_magic_value();
 #endif // JK2_MODE
 
-    if (iCompressedLength > 0)
-    {
-        const auto iLength = -static_cast<int>(io_buffer_.size());
+       if (iCompressedLength > 0)
+       {
+               const auto iLength = -static_cast<int>(io_buffer_.size());
 
-        uiSaved += ::FS_Write(
-            &iLength,
-            static_cast<int>(sizeof(iLength)),
-            file_handle_);
+               uiSaved += ::FS_Write(
+                       &iLength,
+                       static_cast<int>(sizeof(iLength)),
+                       file_handle_);
 
-        uiSaved += ::FS_Write(
-            &iCompressedLength,
-            static_cast<int>(sizeof(iCompressedLength)),
-            file_handle_);
+#ifdef JK2_MODE
+               uiSaved += ::FS_Write(
+                       &uiCksum,
+                       static_cast<int>(sizeof(uiCksum)),
+                       file_handle_);
+#endif // JK2_MODE
 
-        uiSaved += ::FS_Write(
-            rle_buffer_.data(),
-            iCompressedLength,
-            file_handle_);
+               uiSaved += ::FS_Write(
+                       &iCompressedLength,
+                       static_cast<int>(sizeof(iCompressedLength)),
+                       file_handle_);
+
+               uiSaved += ::FS_Write(
+                       rle_buffer_.data(),
+                       iCompressedLength,
+                       file_handle_);
 
 #ifdef JK2_MODE
-        uiSaved += ::FS_Write(
-            &uiMagic,
-            static_cast<int>(sizeof(uiMagic)),
-            file_handle_);
+               uiSaved += ::FS_Write(
+                       &uiMagic,
+                       static_cast<int>(sizeof(uiMagic)),
+                       file_handle_);
 #endif // JK2_MODE
 
 #ifndef JK2_MODE
-        uiSaved += ::FS_Write(
-            &uiCksum,
-            static_cast<int>(sizeof(uiCksum)),
-            file_handle_);
+               uiSaved += ::FS_Write(
+                       &uiCksum,
+                       static_cast<int>(sizeof(uiCksum)),
+                       file_handle_);
 #endif // !JK2_MODE
 
-        if (uiSaved !=
-            sizeof(chunk_id) +
-            sizeof(iLength) +
-            sizeof(uiCksum) +
-            sizeof(iCompressedLength) +
-            iCompressedLength +
+               if (uiSaved !=
+                       sizeof(chunk_id) +
+                       sizeof(iLength) +
+                       sizeof(uiCksum) +
+                       sizeof(iCompressedLength) +
+                       iCompressedLength +
 #ifdef JK2_MODE
-            sizeof(uiMagic) +
+                       sizeof(uiMagic) +
 #endif // JK2_MODE
-            0)
-        {
-            is_write_failed_ = true;
-
-            ::Com_Printf(
-                S_COLOR_RED "Failed to write %s chunk\n",
-                chunk_id_string.c_str());
-
-            return;
-        }
-    }
-    else
-    {
-        const auto iLength = static_cast<uint32_t>(io_buffer_.size());
-
-        uiSaved += ::FS_Write(
-            &iLength,
-            static_cast<int>(sizeof(iLength)),
-            file_handle_);
-
-        uiSaved += ::FS_Write(
-            io_buffer_.data(),
-            iLength,
-            file_handle_);
+                       0)
+               {
+                       is_write_failed_ = true;
+
+                       ::Com_Printf(
+                               S_COLOR_RED "Failed to write %s chunk\n",
+                               chunk_id_string.c_str());
+
+                       return;
+               }
+       }
+       else
+       {
+               const auto iLength = static_cast<uint32_t>(io_buffer_.size());
+
+               uiSaved += ::FS_Write(
+                       &iLength,
+                       static_cast<int>(sizeof(iLength)),
+                       file_handle_);
 
 #ifdef JK2_MODE
-        uiSaved += ::FS_Write(
-            &uiMagic,
-            static_cast<int>(sizeof(uiMagic)),
-            file_handle_);
+               uiSaved += ::FS_Write(
+                       &uiCksum,
+                       static_cast<int>(sizeof(uiCksum)),
+                       file_handle_);
 #endif // JK2_MODE
 
+               uiSaved += ::FS_Write(
+                       io_buffer_.data(),
+                       iLength,
+                       file_handle_);
+
 #ifdef JK2_MODE
-        uiSaved += ::FS_Write(
-            &uiCksum,
-            static_cast<int>(sizeof(uiCksum)),
-            file_handle_);
+               uiSaved += ::FS_Write(
+                       &uiMagic,
+                       static_cast<int>(sizeof(uiMagic)),
+                       file_handle_);
 #endif // JK2_MODE
 
-        if (uiSaved !=
-            sizeof(chunk_id) +
-            sizeof(iLength) +
-            sizeof(uiCksum) +
-            iLength +
+#ifndef JK2_MODE
+               uiSaved += ::FS_Write(
+                       &uiCksum,
+                       static_cast<int>(sizeof(uiCksum)),
+                       file_handle_);
+#endif // !JK2_MODE
+
+               if (uiSaved !=
+                       sizeof(chunk_id) +
+                       sizeof(iLength) +
+                       sizeof(uiCksum) +
+                       iLength +
 #ifdef JK2_MODE
-            sizeof(uiMagic) +
+                       sizeof(uiMagic) +
 #endif // JK2_MODE
-            0)
-        {
-            is_write_failed_ = true;
+                       0)
+               {
+                       is_write_failed_ = true;
 
-            ::Com_Printf(
-                S_COLOR_RED "Failed to write %s chunk\n",
-                chunk_id_string.c_str());
+                       ::Com_Printf(
+                               S_COLOR_RED "Failed to write %s chunk\n",
+                               chunk_id_string.c_str());
 
-            return;
-        }
-    }
+                       return;
+               }
+       }
 }
 
 void SavedGame::raw_read(
-    void* dst_data,
-    int dst_size)
-{
-    if (!dst_data)
-    {
-        throw_error(
-            "Null pointer.");
-    }
-
-    if (dst_size < 0)
-    {
-        throw_error(
-            "Negative size.");
-    }
-
-    if (!is_readable_)
-    {
-        throw_error(
-            "Not readable.");
-    }
-
-    if (dst_size == 0)
-    {
-        return;
-    }
-
-    auto is_overflowed = ((io_buffer_offset_ + dst_size) > io_buffer_.size());
-
-    if (is_overflowed)
-    {
-        if (!is_read_overflow_allowed_)
-        {
-            throw_error(
-                "Not enough data.");
-        }
-    }
-
-    if (!is_overflowed)
-    {
-        std::uninitialized_copy_n(
-            &io_buffer_[io_buffer_offset_],
-            dst_size,
-            static_cast<uint8_t*>(dst_data));
-    }
-
-    io_buffer_offset_ += dst_size;
+       void* dst_data,
+       int dst_size)
+{
+       if (!dst_data)
+       {
+               throw_error(
+                       "Null pointer.");
+       }
+
+       if (dst_size < 0)
+       {
+               throw_error(
+                       "Negative size.");
+       }
+
+       if (!is_readable_)
+       {
+               throw_error(
+                       "Not readable.");
+       }
+
+       if (dst_size == 0)
+       {
+               return;
+       }
+
+       auto is_overflowed = ((io_buffer_offset_ + dst_size) > 
io_buffer_.size());
+
+       if (is_overflowed)
+       {
+               if (!is_read_overflow_allowed_)
+               {
+                       throw_error(
+                               "Not enough data.");
+               }
+       }
+
+       if (!is_overflowed)
+       {
+               std::uninitialized_copy_n(
+                       &io_buffer_[io_buffer_offset_],
+                       dst_size,
+                       static_cast<uint8_t*>(dst_data));
+       }
+
+       io_buffer_offset_ += dst_size;
 }
 
 void SavedGame::raw_write(
-    const void* src_data,
-    int src_size)
+       const void* src_data,
+       int src_size)
 {
-    if (!src_data)
-    {
-        throw_error(
-            "Null pointer.");
-    }
+       if (!src_data)
+       {
+               throw_error(
+                       "Null pointer.");
+       }
 
-    if (src_size < 0)
-    {
-        throw_error(
-            "Negative size.");
-    }
+       if (src_size < 0)
+       {
+               throw_error(
+                       "Negative size.");
+       }
 
-    if (!is_writable_)
-    {
-        throw_error(
-            "Not writable.");
-    }
+       if (!is_writable_)
+       {
+               throw_error(
+                       "Not writable.");
+       }
 
-    if (src_size == 0)
-    {
-        return;
-    }
+       if (src_size == 0)
+       {
+               return;
+       }
 
-    const auto new_buffer_size = io_buffer_offset_ + src_size;
+       const auto new_buffer_size = io_buffer_offset_ + src_size;
 
-    io_buffer_.resize(
-        new_buffer_size);
+       io_buffer_.resize(
+               new_buffer_size);
 
-    std::uninitialized_copy_n(
-        static_cast<const uint8_t*>(src_data),
-        src_size,
-        &io_buffer_[io_buffer_offset_]);
+       std::uninitialized_copy_n(
+               static_cast<const uint8_t*>(src_data),
+               src_size,
+               &io_buffer_[io_buffer_offset_]);
 
-    io_buffer_offset_ = new_buffer_size;
+       io_buffer_offset_ = new_buffer_size;
 }
 
 bool SavedGame::is_write_failed() const
 {
-    return is_write_failed_;
+       return is_write_failed_;
 }
 
 void SavedGame::skip(
-    int count)
-{
-    if (!is_readable_ && !is_writable_)
-    {
-        throw_error(
-            "Not open or created.");
-    }
-
-    if (count < 0)
-    {
-        throw_error(
-            "Negative count.");
-    }
-
-    if (count == 0)
-    {
-        return;
-    }
-
-    const auto new_offset = io_buffer_offset_ + count;
-    const auto buffer_size = io_buffer_.size();
-
-    if (new_offset > buffer_size)
-    {
-        if (is_readable_)
-        {
-            throw_error(
-                "Not enough data.");
-        }
-        else if (is_writable_)
-        {
-            if (new_offset > buffer_size)
-            {
-                io_buffer_.resize(
-                    new_offset);
-            }
-        }
-    }
-
-    io_buffer_offset_ = new_offset;
+       int count)
+{
+       if (!is_readable_ && !is_writable_)
+       {
+               throw_error(
+                       "Not open or created.");
+       }
+
+       if (count < 0)
+       {
+               throw_error(
+                       "Negative count.");
+       }
+
+       if (count == 0)
+       {
+               return;
+       }
+
+       const auto new_offset = io_buffer_offset_ + count;
+       const auto buffer_size = io_buffer_.size();
+
+       if (new_offset > buffer_size)
+       {
+               if (is_readable_)
+               {
+                       throw_error(
+                               "Not enough data.");
+               }
+               else if (is_writable_)
+               {
+                       if (new_offset > buffer_size)
+                       {
+                               io_buffer_.resize(
+                                       new_offset);
+                       }
+               }
+       }
+
+       io_buffer_offset_ = new_offset;
 }
 
 void SavedGame::save_buffer()
 {
-    saved_io_buffer_ = io_buffer_;
-    saved_io_buffer_offset_ = io_buffer_offset_;
+       saved_io_buffer_ = io_buffer_;
+       saved_io_buffer_offset_ = io_buffer_offset_;
 }
 
 void SavedGame::load_buffer()
 {
-    io_buffer_ = saved_io_buffer_;
-    io_buffer_offset_ = saved_io_buffer_offset_;
+       io_buffer_ = saved_io_buffer_;
+       io_buffer_offset_ = saved_io_buffer_offset_;
 }
 
 const void* SavedGame::get_buffer_data() const
 {
-    return io_buffer_.data();
+       return io_buffer_.data();
 }
 
 int SavedGame::get_buffer_size() const
 {
-    return static_cast<int>(io_buffer_.size());
+       return static_cast<int>(io_buffer_.size());
 }
 
 void SavedGame::rename(
-    const std::string& old_base_file_name,
-    const std::string& new_base_file_name)
+       const std::string& old_base_file_name,
+       const std::string& new_base_file_name)
 {
-    const auto&& old_path = generate_path(
-        old_base_file_name);
+       const auto&& old_path = generate_path(
+               old_base_file_name);
 
-    const auto&& new_path = generate_path(
-        new_base_file_name);
+       const auto&& new_path = generate_path(
+               new_base_file_name);
 
-    const auto rename_result = ::FS_MoveUserGenFile(
-        old_path.c_str(),
-        new_path.c_str());
+       const auto rename_result = ::FS_MoveUserGenFile(
+               old_path.c_str(),
+               new_path.c_str());
 
-    if (rename_result == 0)
-    {
-        ::Com_Printf(
-            S_COLOR_RED "Error during savegame-rename."
-                " Check \"%s\" for write-protect or disk full!\n",
-            new_path.c_str());
-    }
+       if (rename_result == 0)
+       {
+               ::Com_Printf(
+                       S_COLOR_RED "Error during savegame-rename."
+                       " Check \"%s\" for write-protect or disk full!\n",
+                       new_path.c_str());
+       }
 }
 
 void SavedGame::remove(
-    const std::string& base_file_name)
+       const std::string& base_file_name)
 {
-    const auto&& path = generate_path(
-        base_file_name);
+       const auto&& path = generate_path(
+               base_file_name);
 
-    ::FS_DeleteUserGenFile(
-        path.c_str());
+       ::FS_DeleteUserGenFile(
+               path.c_str());
 }
 
 SavedGame& SavedGame::get_instance()
 {
-    static SavedGame result;
-    return result;
+       static SavedGame result;
+       return result;
 }
 
 void SavedGame::allow_read_overflow(
-    bool value)
+       bool value)
 {
-    is_read_overflow_allowed_ = value;
+       is_read_overflow_allowed_ = value;
 }
 
 void SavedGame::throw_error(
-    const char* message)
+       const char* message)
 {
-    throw SavedGameException(
-        message);
+       throw SavedGameException(
+               message);
 }
 
 void SavedGame::throw_error(
-    const std::string& message)
+       const std::string& message)
 {
-    throw SavedGameException(
-        message);
+       throw SavedGameException(
+               message);
 }
 
 void SavedGame::compress(
-    const Buffer& src_buffer,
-    Buffer& dst_buffer)
-{
-    const auto src_size = static_cast<int>(src_buffer.size());
-
-    dst_buffer.resize(2 * src_size);
-
-    auto src_count = 0;
-    auto dst_index = 0;
-
-    while (src_count < src_size)
-    {
-        auto src_index = src_count;
-        auto b = src_buffer[src_index++];
-
-        while (src_index < src_size &&
-            (src_index - src_count) < 127 &&
-            src_buffer[src_index] == b)
-        {
-            src_index += 1;
-        }
-
-        if ((src_index - src_count) == 1)
-        {
-            while (src_index < src_size &&
-                (src_index - src_count) < 127 && (
-                    src_buffer[src_index] != src_buffer[src_index - 1] || (
-                        src_index > 1 &&
-                        src_buffer[src_index] != src_buffer[src_index - 2])))
-            {
-                src_index += 1;
-            }
-
-            while (src_index < src_size &&
-                src_buffer[src_index] == src_buffer[src_index - 1])
-            {
-                src_index -= 1;
-            }
-
-            dst_buffer[dst_index++] =
-                static_cast<uint8_t>(src_count - src_index);
-
-            for (auto i = src_count; i < src_index; ++i)
-            {
-                dst_buffer[dst_index++] = src_buffer[i];
-            }
-        }
-        else
-        {
-            dst_buffer[dst_index++] =
-                static_cast<uint8_t>(src_index - src_count);
-
-            dst_buffer[dst_index++] = b;
-        }
-
-        src_count = src_index;
-    }
-
-    dst_buffer.resize(
-        dst_index);
+       const Buffer& src_buffer,
+       Buffer& dst_buffer)
+{
+       const auto src_size = static_cast<int>(src_buffer.size());
+
+       dst_buffer.resize(2 * src_size);
+
+       auto src_count = 0;
+       auto dst_index = 0;
+
+       while (src_count < src_size)
+       {
+               auto src_index = src_count;
+               auto b = src_buffer[src_index++];
+
+               while (src_index < src_size &&
+                       (src_index - src_count) < 127 &&
+                       src_buffer[src_index] == b)
+               {
+                       src_index += 1;
+               }
+
+               if ((src_index - src_count) == 1)
+               {
+                       while (src_index < src_size &&
+                               (src_index - src_count) < 127 && (
+                                       src_buffer[src_index] != 
src_buffer[src_index - 1] || (
+                                               src_index > 1 &&
+                                               src_buffer[src_index] != 
src_buffer[src_index - 2])))
+                       {
+                               src_index += 1;
+                       }
+
+                       while (src_index < src_size &&
+                               src_buffer[src_index] == src_buffer[src_index - 
1])
+                       {
+                               src_index -= 1;
+                       }
+
+                       dst_buffer[dst_index++] =
+                               static_cast<uint8_t>(src_count - src_index);
+
+                       for (auto i = src_count; i < src_index; ++i)
+                       {
+                               dst_buffer[dst_index++] = src_buffer[i];
+                       }
+               }
+               else
+               {
+                       dst_buffer[dst_index++] =
+                               static_cast<uint8_t>(src_index - src_count);
+
+                       dst_buffer[dst_index++] = b;
+               }
+
+               src_count = src_index;
+       }
+
+       dst_buffer.resize(
+               dst_index);
 }
 
 void SavedGame::decompress(
-    const Buffer& src_buffer,
-    Buffer& dst_buffer)
+       const Buffer& src_buffer,
+       Buffer& dst_buffer)
 {
-    auto src_index = 0;
-    auto dst_index = 0;
+       auto src_index = 0;
+       auto dst_index = 0;
 
-    auto remain_size = static_cast<int>(dst_buffer.size());
+       auto remain_size = static_cast<int>(dst_buffer.size());
 
-    while (remain_size > 0)
-    {
-        auto count = static_cast<int8_t>(src_buffer[src_index++]);
+       while (remain_size > 0)
+       {
+               auto count = static_cast<int8_t>(src_buffer[src_index++]);
 
-        if (count > 0)
-        {
-            std::uninitialized_fill_n(
-                &dst_buffer[dst_index],
-                count,
-                src_buffer[src_index++]);
-        }
-        else
-        {
-            if (count < 0)
-            {
-                count = -count;
+               if (count > 0)
+               {
+                       std::uninitialized_fill_n(
+                               &dst_buffer[dst_index],
+                               count,
+                               src_buffer[src_index++]);
+               }
+               else
+               {
+                       if (count < 0)
+                       {
+                               count = -count;
 
-                std::uninitialized_copy_n(
-                    &src_buffer[src_index],
-                    count,
-                    &dst_buffer[dst_index]);
+                               std::uninitialized_copy_n(
+                                       &src_buffer[src_index],
+                                       count,
+                                       &dst_buffer[dst_index]);
 
-                src_index += count;
-            }
-        }
+                               src_index += count;
+                       }
+               }
 
-        dst_index += count;
-        remain_size -= count;
-    }
+               dst_index += count;
+               remain_size -= count;
+       }
 }
 
 std::string SavedGame::generate_path(
-    const std::string& base_file_name)
+       const std::string& base_file_name)
 {
-    auto normalized_file_name = base_file_name;
+       auto normalized_file_name = base_file_name;
 
-    std::replace(
-        normalized_file_name.begin(),
-        normalized_file_name.end(),
-        '/',
-        '_');
+       std::replace(
+               normalized_file_name.begin(),
+               normalized_file_name.end(),
+               '/',
+               '_');
 
-    auto&& path = "saves/" + normalized_file_name + ".sav";
+       auto&& path = "saves/" + normalized_file_name + ".sav";
 
-    return path;
+       return path;
 }
 
 std::string SavedGame::get_chunk_id_string(
-    uint32_t chunk_id)
+       uint32_t chunk_id)
 {
-    std::string result(4, '\0');
+       std::string result(4, '\0');
 
-    result[0] = static_cast<char>((chunk_id >> 24) & 0xFF);
-    result[1] = static_cast<char>((chunk_id >> 16) & 0xFF);
-    result[2] = static_cast<char>((chunk_id >> 8) & 0xFF);
-    result[3] = static_cast<char>((chunk_id >> 0) & 0xFF);
+       result[0] = static_cast<char>((chunk_id >> 24) & 0xFF);
+       result[1] = static_cast<char>((chunk_id >> 16) & 0xFF);
+       result[2] = static_cast<char>((chunk_id >> 8) & 0xFF);
+       result[3] = static_cast<char>((chunk_id >> 0) & 0xFF);
 
-    return result;
+       return result;
 }
 
 void SavedGame::reset_buffer()
 {
-    io_buffer_.clear();
-    reset_buffer_offset();
+       io_buffer_.clear();
+       reset_buffer_offset();
 }
 
 void SavedGame::reset_buffer_offset()
 {
-    io_buffer_offset_ = 0;
+       io_buffer_offset_ = 0;
 }
 
 constexpr uint32_t SavedGame::get_jo_magic_value()
 {
-    return 0x1234ABCD;
+       return 0x1234ABCD;
 }
 
 
diff --git a/shared/qcommon/ojk_saved_game.h b/shared/qcommon/ojk_saved_game.h
index 8b5a9b6..6e874a4 100644
--- a/shared/qcommon/ojk_saved_game.h
+++ b/shared/qcommon/ojk_saved_game.h
@@ -19,193 +19,193 @@ namespace ojk
 
 
 class SavedGame :
-    public ISavedGame
+       public ISavedGame
 {
 public:
-    using ChunkId = uint32_t;
+       using ChunkId = uint32_t;
 
 
-    SavedGame();
+       SavedGame();
 
-    SavedGame(
-        const SavedGame& that) = delete;
+       SavedGame(
+               const SavedGame& that) = delete;
 
-    SavedGame& operator=(
-        const SavedGame& that) = delete;
+       SavedGame& operator=(
+               const SavedGame& that) = delete;
 
-    virtual ~SavedGame();
+       virtual ~SavedGame();
 
 
-    // Creates a new saved game file for writing.
-    bool create(
-        const std::string& base_file_name);
+       // Creates a new saved game file for writing.
+       bool create(
+               const std::string& base_file_name);
 
-    // Opens an existing saved game file for reading.
-    bool open(
-        const std::string& base_file_name);
+       // Opens an existing saved game file for reading.
+       bool open(
+               const std::string& base_file_name);
 
-    // Closes the current saved game file.
-    void close();
+       // Closes the current saved game file.
+       void close();
 
 
-    // Returns true if the saved game opened for reading.
-    bool is_readable() const override;
+       // Returns true if the saved game opened for reading.
+       bool is_readable() const override;
 
-    // Returns true if the saved game opened for writing.
-    bool is_writable() const override;
+       // Returns true if the saved game opened for writing.
+       bool is_writable() const override;
 
 
-    // Reads a chunk from the file into the internal buffer.
-    void read_chunk(
-        const ChunkId chunk_id) override;
+       // Reads a chunk from the file into the internal buffer.
+       void read_chunk(
+               const ChunkId chunk_id) override;
 
-    using ISavedGame::read_chunk;
+       using ISavedGame::read_chunk;
 
 
-    // Returns true if all data read from the internal buffer.
-    bool is_all_data_read() const override;
+       // Returns true if all data read from the internal buffer.
+       bool is_all_data_read() const override;
 
-    // Throws an exception if all data not read.
-    void ensure_all_data_read() const override;
+       // Throws an exception if all data not read.
+       void ensure_all_data_read() const override;
 
 
-    // Writes a chunk into the file from the internal buffer.
-    void write_chunk(
-        const ChunkId chunk_id) override;
+       // Writes a chunk into the file from the internal buffer.
+       void write_chunk(
+               const ChunkId chunk_id) override;
 
-    using ISavedGame::write_chunk;
+       using ISavedGame::write_chunk;
 
 
-    // Reads a raw data from the internal buffer.
-    void raw_read(
-        void* dst_data,
-        int dst_size) override;
+       // Reads a raw data from the internal buffer.
+       void raw_read(
+               void* dst_data,
+               int dst_size) override;
 
-    using ISavedGame::read;
+       using ISavedGame::read;
 
 
-    // Writes a raw data into the internal buffer.
-    void raw_write(
-        const void* src_data,
-        int src_size) override;
+       // Writes a raw data into the internal buffer.
+       void raw_write(
+               const void* src_data,
+               int src_size) override;
 
-    using ISavedGame::write;
+       using ISavedGame::write;
 
 
-    bool is_write_failed() const;
+       bool is_write_failed() const;
 
-    // Increments buffer's offset by the specified non-negative count.
-    void skip(
-        int count) override;
+       // Increments buffer's offset by the specified non-negative count.
+       void skip(
+               int count) override;
 
 
-    // Stores current I/O buffer and it's position.
-    void save_buffer() override;
+       // Stores current I/O buffer and it's position.
+       void save_buffer() override;
 
-    // Restores saved I/O buffer and it's position.
-    void load_buffer() override;
+       // Restores saved I/O buffer and it's position.
+       void load_buffer() override;
 
 
-    // Returns a pointer to data in the I/O buffer.
-    const void* get_buffer_data() const override;
+       // Returns a pointer to data in the I/O buffer.
+       const void* get_buffer_data() const override;
 
-    // Returns a current size of the I/O buffer.
-    int get_buffer_size() const override;
+       // Returns a current size of the I/O buffer.
+       int get_buffer_size() const override;
 
 
-    // Clears buffer and resets it's offset to the beginning.
-    void reset_buffer() override;
+       // Clears buffer and resets it's offset to the beginning.
+       void reset_buffer() override;
 
-    // Resets buffer offset to the beginning.
-    void reset_buffer_offset() override;
+       // Resets buffer offset to the beginning.
+       void reset_buffer_offset() override;
 
 
-    // Renames a saved game file.
-    static void rename(
-        const std::string& old_base_file_name,
-        const std::string& new_base_file_name);
+       // Renames a saved game file.
+       static void rename(
+               const std::string& old_base_file_name,
+               const std::string& new_base_file_name);
 
-    // Remove a saved game file.
-    static void remove(
-        const std::string& base_file_name);
+       // Remove a saved game file.
+       static void remove(
+               const std::string& base_file_name);
 
-    // Returns a default instance of the class.
-    static SavedGame& get_instance();
+       // Returns a default instance of the class.
+       static SavedGame& get_instance();
 
 
 protected:
-    // If true won't throw an exception when buffer offset is beyond it's size.
-    // Although, no data will be read beyond the buffer.
-    void allow_read_overflow(
-        bool value) override;
+       // If true won't throw an exception when buffer offset is beyond it's 
size.
+       // Although, no data will be read beyond the buffer.
+       void allow_read_overflow(
+               bool value) override;
 
 
 private:
-    using Buffer = std::vector<uint8_t>;
-    using BufferOffset = Buffer::size_type;
-    using Paths = std::vector<std::string>;
+       using Buffer = std::vector<uint8_t>;
+       using BufferOffset = Buffer::size_type;
+       using Paths = std::vector<std::string>;
 
 
-    // A handle to a file.
-    int32_t file_handle_;
+       // A handle to a file.
+       int32_t file_handle_;
 
-    // I/O buffer.
-    Buffer io_buffer_;
+       // I/O buffer.
+       Buffer io_buffer_;
 
-    // Saved copy of the I/O buffer.
-    Buffer saved_io_buffer_;
+       // Saved copy of the I/O buffer.
+       Buffer saved_io_buffer_;
 
-    // A current offset inside the I/O buffer.
-    BufferOffset io_buffer_offset_;
+       // A current offset inside the I/O buffer.
+       BufferOffset io_buffer_offset_;
 
-    // Saved I/O buffer offset.
-    BufferOffset saved_io_buffer_offset_;
+       // Saved I/O buffer offset.
+       BufferOffset saved_io_buffer_offset_;
 
-    // RLE codec buffer.
-    Buffer rle_buffer_;
+       // RLE codec buffer.
+       Buffer rle_buffer_;
 
-    // True if saved game opened for reading.
-    bool is_readable_;
+       // True if saved game opened for reading.
+       bool is_readable_;
 
-    // True if saved game opened for writing.
-    bool is_writable_;
+       // True if saved game opened for writing.
+       bool is_writable_;
 
-    // True if any previous write operation failed.
-    bool is_write_failed_;
+       // True if any previous write operation failed.
+       bool is_write_failed_;
 
-    // Controls exception throw on read overflow.
-    bool is_read_overflow_allowed_;
+       // Controls exception throw on read overflow.
+       bool is_read_overflow_allowed_;
 
 
-    // Throws an exception.
-    static void throw_error(
-        const char* message);
+       // Throws an exception.
+       static void throw_error(
+               const char* message);
 
-    // Throws an exception.
-    static void throw_error(
-        const std::string& message);
+       // Throws an exception.
+       static void throw_error(
+               const std::string& message);
 
 
-    // Compresses data.
-    static void compress(
-        const Buffer& src_buffer,
-        Buffer& dst_buffer);
+       // Compresses data.
+       static void compress(
+               const Buffer& src_buffer,
+               Buffer& dst_buffer);
 
-    // Decompresses data.
-    static void decompress(
-        const Buffer& src_buffer,
-        Buffer& dst_buffer);
+       // Decompresses data.
+       static void decompress(
+               const Buffer& src_buffer,
+               Buffer& dst_buffer);
 
 
-    static std::string generate_path(
-        const std::string& base_file_name);
+       static std::string generate_path(
+               const std::string& base_file_name);
 
 
-    // Returns a string representation of a chunk id.
-    static std::string get_chunk_id_string(
-        uint32_t chunk_id);
+       // Returns a string representation of a chunk id.
+       static std::string get_chunk_id_string(
+               uint32_t chunk_id);
 
-    static constexpr uint32_t get_jo_magic_value();
+       static constexpr uint32_t get_jo_magic_value();
 }; // SavedGame
 
 

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-games/openjk.git

_______________________________________________
Pkg-games-commits mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits

Reply via email to