Compare commits

..

3 Commits

Author SHA1 Message Date
Joca 4366720dd9
Add final config.ini 2025-12-27 11:02:35 -03:00
Joca d9e6e808d8
Add build directives to most cpp files 2025-12-27 10:53:06 -03:00
BodgeMaster 53173dd7c7 lib/zlibutil, tools/zlibutil: moving things around
This includes the following changes:
- Move the data type wrangling into the lib to make it easier to use
- Put the functions into their own `zlib` namespace
- Use ErrorOr instead of exceptions
- Error codes for compression/decompression
2024-06-10 06:29:30 +02:00
16 changed files with 156 additions and 153 deletions

99
config.ini Normal file
View File

@ -0,0 +1,99 @@
# Project
project_name = fossvg
src_dir = src
build_dir = build
bin_dir = bin
# Build modes
debug = false
optimize = false
verbose = false
# Compiler
compiler = g++
include_dirs = include,src/lib
lib_search_paths = bin/lib
# Global libraries (system libs). Add lib names without '-l'.
# Examples: pthread, z
libraries = pthread
# Global flags
cflags = -Wall -Wextra
ldflags =
# static linking
# you should probaly disable this and add bin/lib/*.a to lib_search_paths instead
static_link = true
# Parallel compilation (use bounded worker pool)
parallel_compilation = true
# Shaders
shaders_dir = bin/shaders
# Dependencies directory (where to look for vendored tools like shaderc)
dependencies_dir = dependencies
# This is hardly a dependency, but we need to run it before building anything else
[dependencies]
name = endianess
build_cmds = g++ -o resources/check_endianness resources/check_endianness.cpp && bash -c resources/check_endianness >> include/endianness
[dependencies]
name = zlib
url = https://www.zlib.net/zlib-1.3.1.tar.xz
archive = zlib.tar.xz
checksum = 38ef96b8dfe510d42707d9c781877914792541133e1870841463bfa73f883e32
extract_to = zlib-1.3.1
build_cmds = ./configure; make; cp -r ../zlib-1.3.1 ../../include/zlib; mkdir -p ../../bin/lib/; cp libz.so.1.3.1 ../../bin/lib/libz.so; cp libz.a ../../bin/lib/libz.a
[dependencies]
name = tiny-utf8
url = https://github.com/DuffsDevice/tiny-utf8/archive/refs/tags/v4.4.3.tar.gz
archive = tiny-utf8.tar.gz
checksum = 8e3f61651909c9f3105d3501932a96aa65733127fb6e7cf94cb1b0a2dff42c8f
extract_to = tiny-utf8-4.4.3
build_cmds = cp -r include/tinyutf8 ../../include/tinyutf8
[dependencies]
name = sockpp
url = https://github.com/fpagliughi/sockpp/archive/refs/tags/v0.8.1.tar.gz
archive = sockpp.tar.gz
checksum = a8aedff8bd8c1da530b91be650352008fddabc9f1df0d19701d76cbc359c8651
extract_to = sockpp-0.8.1
build_cmds = cmake -Bbuild -DSOCKPP_BUILD_STATIC=ON .; cmake --build build; cp -r include/* ../../include/; mkdir -p ../../bin/lib/; cp build/libsockpp.so.0.8.1 ../../bin/lib/libsockpp.so; cp build/libsockpp.a ../../bin/lib/libsockpp.a
[tools]
name = arraydump
sources = src/tools/arraydump.cpp
libraries = cli,file
include_dirs = include
output_dir = bin/tools
[tools]
name = baseconvert
sources = src/tools/baseconvert.cpp
libraries = cli
include_dirs = include
output_dir = bin/tools
[tools]
name = dumpnbt
sources = src/tools/dumpnbt.cpp
libraries = nbt,cli
include_dirs = include
output_dir = bin/tools
[tools]
name = hexnet
sources = src/tools/hexnet.cpp
libraries = cli,libsockpp
include_dirs = include
output_dir = bin/tools
[tools]
name = zlibutil
sources = src/tools/zlibutil.cpp
libraries = cli,file,libz,zlibutil
include_dirs = include
output_dir = bin/tools

View File

@ -70,24 +70,24 @@ fi
popd >/dev/null 2>&1
echo ">>> done"
#echo ">>> Dealing with shaderc shenanigans..."
#pushd dependencies/tmp/shaderc
#echo "Getting sources using the provided script..."
#./update_shaderc_sources.py
#SHADERC_BUILD="build-$(dd if=/dev/urandom bs=1 count=5 2>/dev/null | base32)"
#echo "Creating and entering directory $SHADERC_BUILD."
#mkdir "$SHADERC_BUILD"
#cd "$SHADERC_BUILD"
#echo "Running CMake..."
#CXXFLAGS="-Wno-error" cmake -GNinja -DCMAKE_BUILD_TYPE=Release ../src/
#echo "Running Ninja..."
#ninja
#popd >/dev/null 2>&1
echo ">>> Dealing with shaderc shenanigans..."
pushd dependencies/tmp/shaderc
echo "Getting sources using the provided script..."
./update_shaderc_sources.py
SHADERC_BUILD="build-$(dd if=/dev/urandom bs=1 count=5 2>/dev/null | base32)"
echo "Creating and entering directory $SHADERC_BUILD."
mkdir "$SHADERC_BUILD"
cd "$SHADERC_BUILD"
echo "Running CMake..."
CXXFLAGS="-Wno-error" cmake -GNinja -DCMAKE_BUILD_TYPE=Release ../src/
echo "Running Ninja..."
ninja
popd >/dev/null 2>&1
#if needed copy more relevant files to dependencies/shaderc
#echo "Copying binary to dependencies/shaderc/bin..."
#mkdir -vp dependencies/shaderc/bin
#cp -v "dependencies/tmp/shaderc/$SHADERC_BUILD/glslc/glslc" dependencies/shaderc/bin
#echo ">>> done"
echo "Copying binary to dependencies/shaderc/bin..."
mkdir -vp dependencies/shaderc/bin
cp -v "dependencies/tmp/shaderc/$SHADERC_BUILD/glslc/glslc" dependencies/shaderc/bin
echo ">>> done"
echo ">>> Building zlib..."
pushd dependencies/zlib-1.3.1/

View File

@ -1,3 +1,8 @@
// build-directive: unit-name(fossvg)
// build-directive: link(cli.so)
// build-directive: ldflags(-lglfw -lrt -lm -ldl)
// build-directive: out(fossvg)
// build-directive: static(false)
// Copyright 2022, FOSS-VG Developers and Contributers
//
// Author(s):

View File

@ -1,3 +1,7 @@
// build-directive: unit-name(lib/cli)
// build-directive: out(lib/cli)
// build-directive: shared(true)
// build-directive: cflags(-fPIC -std=c++20)
// Copyright 2022, FOSS-VG Developers and Contributers
//
// Author(s):

View File

@ -1,3 +1,7 @@
// build-directive: unit-name(lib/file)
// build-directive: out(lib/file)
// build-directive: shared(true)
// build-directive: cflags(-fPIC)
// Copyright 2022, FOSS-VG Developers and Contributers
//
// Author(s):

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -18,7 +18,7 @@
#include <tinyutf8/tinyutf8.h>
#include <string>
#include "error.hpp"
#include "../../.endianness"
#include "endianness"
#ifdef FOSSVG_ENDIAN_BIG_WORD
#error "Honeywell-316-style endianness is not supported. If you feel like it should, feel free to participate in the project to maintain it."

View File

@ -1,3 +1,7 @@
// build-directive: unit-name(lib/nbt)
// build-directive: out(lib/nbt)
// build-directive: shared(true)
// build-directive: cflags(-fPIC)
// Copyright 2022, FOSS-VG Developers and Contributers
//
// This program is free software: you can redistribute it and/or modify it
@ -23,7 +27,7 @@
#include "javacompat.hpp"
#include "../../.endianness"
#include "endianness"
#ifdef FOSSVG_ENDIAN_BIG_WORD
#error "Honeywell-316-style endianness is not supported. If you feel like it should, feel free to participate in the project to maintain it."
#endif

View File

@ -20,7 +20,7 @@
#include <string>
#include "../error.hpp"
#include "error.hpp"
namespace network {
struct Connection {

View File

@ -1,3 +1,7 @@
// build-directive: unit-name(lib/net/tcp_client)
// build-directive: out(lib/net/tcp_client)
// build-directive: shared(true)
// build-directive: cflags(-fPIC)
// Copyright 2022, FOSS-VG Developers and Contributers
//
// Author(s):

View File

@ -1,3 +1,7 @@
// build-directive: unit-name(lib/net/tcp_server)
// build-directive: out(lib/net/tcp_server)
// build-directive: shared(true)
// build-directive: cflags(-fPIC)
// Copyright 2022, FOSS-VG Developers and Contributers
//
// Author(s):

View File

@ -1,3 +1,7 @@
// build-directive: unit-name(lib/region)
// build-directive: out(lib/region)
// build-directive: shared(true)
// build-directive: cflags(-fPIC)
// Copyright 2023, FOSS-VG Developers and Contributers
//
// Author(s):

View File

@ -1,3 +1,7 @@
// build-directive: unit-name(lib/zlibutil)
// build-directive: out(lib/zlibutil)
// build-directive: shared(true)
// build-directive: cflags(-fPIC)
// Copyright 2022, FOSS-VG Developers and Contributers
//
// Author(s):

View File

@ -1,131 +0,0 @@
/*
Copyright 2024, FOSS-VG Developers and Contributers
Author(s):
Jocadbz
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, version 3.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
version 3 along with this program.
If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <cstdint>
#include <cstring>
using namespace std;
/*
* Ok, before you read this, please understand.
* This is not a elaborate program. We are not
* using fancy parsers.
* I'm straight up rawdogging the .mca files
* here. Of course this should be fixed, but
* don't get mad.
*/
// Define constants related to .mca file format
const int SECTOR_SIZE = 4096;
const int CHUNK_OFFSET = 4; // Offset where chunk data starts within a sector
const int CHUNK_SIZE = 4096; // Size of a chunk data block
const int HEADER_SIZE = 4;
const int TIMESTAMP_SIZE = 4;
const int NUM_CHUNKS_PER_REGION = 1024; // 32x32 chunks per region file
// Function to extract chunks from a .mca file
// Function to extract chunks from a .mca file and print position, offset, and timestamp
void extractChunks(const string& mcaFilename) {
ifstream file(mcaFilename, ios::binary);
if (!file.is_open()) {
cerr << "Error opening file: " << mcaFilename << endl;
return;
}
// Calculate the number of sectors in the file
file.seekg(0, ios::end);
int fileSize = file.tellg();
int numSectors = fileSize / SECTOR_SIZE;
// Print header information
cout << "Position (x, z), Offset, Timestamp:" << endl;
// Iterate through each sector
for (int sector = 0; sector < numSectors; ++sector) {
// Read the sector header (4 bytes)
file.seekg(sector * SECTOR_SIZE);
char header[HEADER_SIZE];
file.read(header, HEADER_SIZE);
// Extract position (x, z) from the sector header
int x = sector % NUM_CHUNKS_PER_REGION;
int z = sector / NUM_CHUNKS_PER_REGION;
// Calculate offset and timestamp positions
int offset = sector * SECTOR_SIZE + HEADER_SIZE;
int timestampOffset = sector * SECTOR_SIZE + HEADER_SIZE + CHUNK_SIZE;
// Read the timestamp (4 bytes) from the sector
file.seekg(timestampOffset);
char timestampBytes[TIMESTAMP_SIZE];
file.read(timestampBytes, TIMESTAMP_SIZE);
int timestamp = *reinterpret_cast<int*>(timestampBytes);
// Print formatted information
cout << "(" << x << ", " << z << "), " << offset << ", " << timestamp << endl;
}
file.close();
}
// Function to add or replace a chunk in a .mca file
void addReplaceChunk(const string& mcaFilename, int sectorIndex, const vector<uint8_t>& newChunkData) {
fstream file(mcaFilename, ios::in | ios::out | ios::binary);
if (!file.is_open()) {
cerr << "Error opening file: " << mcaFilename << endl;
return;
}
// Calculate the offset in the file where the chunk should be written
int fileOffset = sectorIndex * SECTOR_SIZE + CHUNK_OFFSET;
// Seek to the appropriate position in the file
file.seekp(fileOffset);
// Write the new chunk data
file.write(reinterpret_cast<const char*>(newChunkData.data()), newChunkData.size());
file.close();
cout << "Chunk added/replaced successfully at sector " << sectorIndex << endl;
}
int main() {
// TODO: Remember to implement CLI here.
string mcaFilename = "r.0.0.mca"; // Example .mca file path
// Example: Extract chunks from the .mca file
extractChunks(mcaFilename);
// Example: Add or replace a chunk in the .mca file
int sectorIndex = 0; // Example: Replace the chunk in the first sector
vector<uint8_t> newChunkData(CHUNK_SIZE, 0); // Example: New chunk data (all zeroes for demonstration)
addReplaceChunk(mcaFilename, sectorIndex, newChunkData);
extractChunks(mcaFilename);
return 0;
}

View File

@ -31,8 +31,8 @@
#include <thread>
#include <vector>
#include "../lib/cli.hpp"
#include "../lib/error.hpp"
#include "cli.hpp"
#include "error.hpp"
#define EXIT_SUCCESS 0
#define EXIT_RUNTIME 1