summaryrefslogtreecommitdiff
path: root/include/file
diff options
context:
space:
mode:
authorhovertank3d <[email protected]>2025-11-14 20:05:59 +0100
committerhovertank3d <[email protected]>2025-11-15 14:03:07 +0100
commitfa318825ef0404816728f733484caa1bc23afa53 (patch)
tree154d51e23f907102cbb8367b8cdc4d3bb4153dc1 /include/file
parent6c1a6c62bb13d09a0beb51ebb5cd5e4a69d9fe5a (diff)
downloadogurec-fa318825ef0404816728f733484caa1bc23afa53.tar.gz
ogurec-fa318825ef0404816728f733484caa1bc23afa53.zip
george droid
Diffstat (limited to 'include/file')
-rw-r--r--include/file/metadata.hpp54
-rw-r--r--include/file/world.hpp65
2 files changed, 119 insertions, 0 deletions
diff --git a/include/file/metadata.hpp b/include/file/metadata.hpp
new file mode 100644
index 0000000..8b9ec4f
--- /dev/null
+++ b/include/file/metadata.hpp
@@ -0,0 +1,54 @@
+#pragma once
+
+#include "util/bitset.hpp"
+#include "util/io.hpp"
+#include <cstdint>
+#include <cstdio>
+#include <stdexcept>
+
+namespace file {
+
+enum class filetype : uint8_t {
+ Map = 1,
+ World,
+ Player,
+ TOTAL,
+};
+
+struct metadata {
+ static constexpr auto magic = 27981915666277746uL;
+ static constexpr auto magic_mask = 0xFFFFFFFFFFFFFFuL;
+ static constexpr auto size = 20;
+
+ enum class flags {
+ Favorite,
+ };
+
+ filetype ftype;
+ uint32_t revision;
+ bitset<64> flags;
+
+ template <class T>
+ ssize_t read(io::serialized_io<T>& io)
+ {
+ uint64_t filemagic;
+ auto bytes = io.read(filemagic);
+ if ((filemagic & magic_mask) != magic) {
+ throw std::runtime_error("not a relogic file");
+ }
+
+ uint8_t type = ((filemagic >> 56) & 0xFF);
+ if (type == 0 || type >= int(filetype::TOTAL)) {
+ throw std::runtime_error("unknown file type");
+ }
+
+ ftype = filetype(type);
+
+ bytes += io.read(revision);
+ bytes += io.read(flags);
+
+ return bytes;
+ }
+};
+
+} \ No newline at end of file
diff --git a/include/file/world.hpp b/include/file/world.hpp
new file mode 100644
index 0000000..300a3e0
--- /dev/null
+++ b/include/file/world.hpp
@@ -0,0 +1,65 @@
+#pragma once
+
+#include <array>
+#include <cstdint>
+#include <cstdio>
+#include <fcntl.h>
+#include <filesystem>
+#include <fstream>
+#include <iostream>
+#include <stdexcept>
+#include <string>
+#include <vector>
+
+#include "file/metadata.hpp"
+#include "util/bitset.hpp"
+#include "util/io.hpp"
+#include "version.hpp"
+
+namespace file {
+
+class world {
+ int32_t version;
+ // metadata meta;
+
+ std::vector<uint32_t> positions;
+ bitset<0> importance;
+
+ int32_t seed;
+ std::array<uint8_t, 16> guid;
+ int32_t worldID;
+ int32_t world_left;
+ int32_t world_right;
+ int32_t world_top;
+ int32_t world_botton;
+ int32_t height;
+ int32_t width;
+
+public:
+ void load_header(std::ifstream& f)
+ {
+ }
+
+ world(std::string filename)
+ {
+ if (!std::filesystem::exists(filename)) {
+ throw std::runtime_error("file not found");
+ }
+ auto rw = io::serialized_io(io::file_io { filename });
+
+ rw.read(version);
+ if (version <= 88 || version > terraria_version) {
+ throw std::runtime_error("invalid world file version");
+ }
+ std::cout << version << std::endl;
+ metadata meta;
+
+ rw.read(meta);
+
+ if (meta.ftype != filetype::World) {
+ throw std::runtime_error("expected world file");
+ }
+ }
+};
+
+} \ No newline at end of file