diff --git a/build/stdex.props b/build/stdex.props
new file mode 100644
index 000000000..00a2cb8ec
--- /dev/null
+++ b/build/stdex.props
@@ -0,0 +1,20 @@
+
+
+
+
+ 10
+
+
+ ..\..\..\output\$(Platform).$(Configuration)\
+
+
+
+ STDEX;%(PreprocessorDefinitions)
+
+
+
+
+ $(stdexVersion)
+
+
+
\ No newline at end of file
diff --git a/build/stdex.vcxproj b/build/stdex.vcxproj
new file mode 100644
index 000000000..0f0f2679f
--- /dev/null
+++ b/build/stdex.vcxproj
@@ -0,0 +1,107 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ Win32
+
+
+ Release
+ x64
+
+
+
+
+ Create
+ Create
+ Create
+ Create
+
+
+
+
+
+
+
+
+
+
+
+ {518777CC-0A59-4415-A12A-82751ED75343}
+ stdex
+
+
+
+ DynamicLibrary
+ true
+ Unicode
+
+
+ DynamicLibrary
+ true
+ Unicode
+
+
+ DynamicLibrary
+ false
+ true
+ Unicode
+
+
+ DynamicLibrary
+ false
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $(ProjectName)$(stdexVersion)ud_vc$(PlatformToolsetVersion)
+
+
+ $(ProjectName)$(stdexVersion)ud_vc$(PlatformToolsetVersion)_$(Platform)
+
+
+ $(ProjectName)$(stdexVersion)u_vc$(PlatformToolsetVersion)
+
+
+ $(ProjectName)$(stdexVersion)u_vc$(PlatformToolsetVersion)_$(Platform)
+
+
+
+
+
\ No newline at end of file
diff --git a/build/stdex.vcxproj.filters b/build/stdex.vcxproj.filters
new file mode 100644
index 000000000..a5f4b54f1
--- /dev/null
+++ b/build/stdex.vcxproj.filters
@@ -0,0 +1,38 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hpp;hxx;hm;inl;inc;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+
+
+
+ Source Files
+
+
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+
+
+ Resource Files
+
+
+
\ No newline at end of file
diff --git a/include/stdex/common.h b/include/stdex/common.h
new file mode 100644
index 000000000..052860144
--- /dev/null
+++ b/include/stdex/common.h
@@ -0,0 +1,57 @@
+/*
+ Copyright 2016 Amebis
+
+ This file is part of stdex.
+
+ stdex is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ stdex is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with stdex. If not, see .
+*/
+
+#pragma once
+
+#include
+
+
+///
+/// Public function calling convention
+///
+#ifdef STDEX
+#define STDEX_API __declspec(dllexport)
+#else
+#define STDEX_API __declspec(dllimport)
+#endif
+#define STDEX_NOVTABLE __declspec(novtable)
+
+
+//
+// Product version as a single DWORD
+// Note: Used for version comparison within C/C++ code.
+//
+#define STDEX_VERSION 0x01000000
+
+//
+// Product version by components
+// Note: Resource Compiler has limited preprocessing capability,
+// thus we need to specify major, minor and other version components
+// separately.
+//
+#define STDEX_VERSION_MAJ 1
+#define STDEX_VERSION_MIN 0
+#define STDEX_VERSION_REV 0
+#define STDEX_VERSION_BUILD 0
+
+//
+// Human readable product version and build year for UI
+//
+#define STDEX_VERSION_STR "1.0"
+#define STDEX_BUILD_YEAR_STR "2016"
diff --git a/include/stdex/idrec.h b/include/stdex/idrec.h
new file mode 100644
index 000000000..ac6b08190
--- /dev/null
+++ b/include/stdex/idrec.h
@@ -0,0 +1,263 @@
+/*
+ Copyright 2016 Amebis
+
+ This file is part of stdex.
+
+ stdex is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ stdex is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with stdex. If not, see .
+*/
+
+#pragma once
+
+#include "common.h"
+
+#include
+
+
+namespace stdex {
+ namespace idrec {
+ ///
+ /// Skips current record data
+ ///
+ /// \param[in] stream Input stream
+ ///
+ /// \returns
+ /// - true when successful
+ /// - false otherwise
+ ///
+ template
+ inline bool ignore(T_STREAM& stream)
+ {
+ T_SIZE size;
+
+ // Read record size.
+ stream.read(&size, sizeof(size));
+ if (stream.fail()) return false;
+
+ // Skip the record data.
+ size += (T_SIZE)(ALIGN - size) % ALIGN;
+ stream.ignore(size);
+ if (stream.fail()) return false;
+
+ return true;
+ }
+
+
+ ///
+ /// Finds record data
+ ///
+ /// \param[in] stream Input stream
+ /// \param[in] id Record ID
+ /// \param[in] end Position limit. Default is -1 (no limit).
+ ///
+ /// \returns
+ /// - true when found
+ /// - false otherwise
+ ///
+ template
+ inline bool find(T_STREAM& stream, T_ID id, std::streamoff end = (std::streamoff)-1)
+ {
+ T_ID _id;
+
+ while (end == (std::streamoff)-1 || stream.tellg() < end) {
+ stream.read(&_id, sizeof(_id));
+ if (stream.fail()) return false;
+
+ if (_id == id) {
+ // The record was found.
+ return true;
+ } else
+ ignore(stream);
+ }
+
+ return false;
+ }
+
+
+ ///
+ /// Writes record header
+ ///
+ /// \param[in] stream Output stream
+ /// \param[in] id Record ID
+ ///
+ /// \returns Position of the record header start in \p stream. Save for later \c close call.
+ ///
+ template
+ inline std::streamoff open(T_STREAM& stream, T_ID id)
+ {
+ std::streamoff start = stream.tellp();
+
+ // Write ID.
+ if (stream.fail()) return (std::streamoff)-1;
+ stream.write(&id, sizeof(id));
+
+ // Write 0 as a placeholder for data size.
+ if (stream.fail()) return (std::streamoff)-1;
+ stream.write(&(T_SIZE)0, sizeof(T_SIZE));
+
+ return start;
+ }
+
+
+ ///
+ /// Updates record header
+ ///
+ /// \param[in] stream Output stream
+ /// \param[in] start Start position of the record in \p stream
+ ///
+ /// \returns Position of the record end in \p stream
+ ///
+ template
+ inline std::streamoff close(T_STREAM& stream, std::streamoff start)
+ {
+ std::streamoff end = stream.tellp();
+ T_SIZE
+ size = (T_SIZE)(end - start - sizeof(T_ID) - sizeof(T_SIZE)),
+ remainder = (T_SIZE)(ALIGN - size) % ALIGN; // Number of bytes we need to add, to keep the data integral number of ALIGN blocks long
+
+ if (remainder) {
+ // Append padding.
+ static const unsigned char padding[ALIGN] = {};
+ stream.write(padding, remainder);
+ end += remainder;
+ }
+
+ // Update the data size.
+ if (stream.fail()) return (std::streamoff)-1;
+ stream.seekp(start + sizeof(T_ID));
+ stream.write(&size, sizeof(size));
+ stream.seekp(end);
+
+ return end;
+ }
+
+
+ ///
+ /// Helper struct for read/write of records to/from memory
+ ///
+ template
+ struct STDEX_API record
+ {
+ ///
+ /// Constructs the struct
+ ///
+ inline record( T &_data) : data( _data) {}
+ inline record(const T &_data) : data((T&)_data) {}
+
+
+ ///
+ /// Assignment operator
+ ///
+ /// \param[in] r Source record
+ ///
+ /// \returns A const reference to this struct
+ ///
+ inline const record& operator =(const record &r)
+ {
+ data = r.data;
+ return *this;
+ }
+
+
+ ///
+ /// Writes record header
+ ///
+ /// \param[in] stream Output stream
+ ///
+ /// \returns Position of the record header start in \p stream. Save for later \c close call.
+ ///
+ template
+ static inline std::streamoff open(T_STREAM& stream)
+ {
+ return open(stream, id);
+ }
+
+
+ ///
+ /// Updates record header
+ ///
+ /// \param[in] stream Output stream
+ /// \param[in] start Start position of the record in \p stream
+ ///
+ /// \returns Position of the record end in \p stream
+ ///
+ template
+ static inline std::streamoff close(T_STREAM& stream, std::streamoff start)
+ {
+ return close(stream, start);
+ }
+
+
+ ///
+ /// Finds record data
+ ///
+ /// \param[in] stream Input stream
+ /// \param[in] end Position limit. Default is -1 (no limit).
+ ///
+ /// \returns
+ /// - true when found
+ /// - false otherwise
+ ///
+ template
+ static inline bool find(T_STREAM& stream, std::streamoff end = (std::streamoff)-1)
+ {
+ return find(stream, id, end);
+ }
+
+ static const T_ID id; ///< Record id
+ T &data; ///< Record data reference
+ };
+ };
+};
+
+
+template
+inline T_STREAM& operator <<(T_STREAM& stream, const stdex::idrec::record r)
+{
+ // Parameter r does not need to be passed by reference. It has only one field (data), which is a reference itself already. The id field is static anyway.
+
+ if (stream.fail()) return stream;
+ std::streamoff start = r.open(stream);
+
+ if (stream.fail()) return stream;
+ stream << r.data;
+
+ if (stream.fail()) return stream;
+ r.close(stream, start);
+
+ return stream;
+}
+
+
+template
+inline T_STREAM& operator >>(T_STREAM& stream, stdex::idrec::record r)
+{
+ // Parameter r does not need to be passed by reference. It has only one field (data), which is a reference itself already. The id field is static anyway.
+
+ // Read data size.
+ T_SIZE size;
+ stream.read(size, sizeof(size));
+ if (stream.fail()) return stream;
+
+ // Read data.
+ std::streamoff start = stream.tellg();
+ {
+ ROmejenaDatoteka _stream(&stream, start, size);
+ _stream >> r.data;
+ }
+
+ size += (T_SIZE)(ALIGN - size) % ALIGN;
+ stream.seekg(start + size);
+
+ return stream;
+}
diff --git a/res/stdex.rc b/res/stdex.rc
new file mode 100644
index 000000000..25c723044
Binary files /dev/null and b/res/stdex.rc differ
diff --git a/src/stdafx.cpp b/src/stdafx.cpp
new file mode 100644
index 000000000..c1f16b90c
--- /dev/null
+++ b/src/stdafx.cpp
@@ -0,0 +1,20 @@
+/*
+ Copyright 2016 Amebis
+
+ This file is part of stdex.
+
+ stdex is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ stdex is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with stdex. If not, see .
+*/
+
+#include "stdafx.h"
diff --git a/src/stdafx.h b/src/stdafx.h
new file mode 100644
index 000000000..6ea62506f
--- /dev/null
+++ b/src/stdafx.h
@@ -0,0 +1,22 @@
+/*
+ Copyright 2016 Amebis
+
+ This file is part of stdex.
+
+ stdex is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ stdex is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with stdex. If not, see .
+*/
+
+#pragma once
+
+#include "../include/stdex/idrec.h"