<commit_before>#pragma once
#include <fstream>
#include <iostream>
#include <memory>
#include "structs.h"
#include "fileFunctions.h"
#include <string>

namespace RELPatch {

	class RELFile {
	public:

	private:
		std::unique_ptr<Header> header;
		std::unique_ptr<SectionInfoTable[]> sectionInfoTable;
		std::unique_ptr<ImportTable[]> importTable;
		std::fstream relFile;

	public:
		RELFile(char *filename) {
			relFile.open(filename, std::ios::binary | std::ios::in | std::ios::out);
			if (relFile.is_open()) {
				parseRel();
			}
		}

		RELFile(std::string filename) {
			relFile.open(filename, std::ios::binary | std::ios::in | std::ios::out);
			if (relFile.is_open()) {
				parseRel();
			}
		}

		~RELFile() {
			if (relFile.is_open()) {
				relFile.close();
			}
		}

		void writeToSection(uint32_t sectionID, uint32_t offset, uint32_t value) {
			if (validSection(sectionID)) {
				relFile.seekg(toAddress(sectionInfoTable[sectionID].offset, offset), std::fstream::beg);
				writeBigInt(relFile, value);
			}
		}

		void writeToSection(uint32_t sectionID, uint32_t offset, uint16_t value) {
			if (validSection(sectionID)) {
				relFile.seekg(toAddress(sectionInfoTable[sectionID].offset, offset), std::fstream::beg);
				writeBigShort(relFile, value);
			}
		}

		void writeToSection(uint32_t sectionID, uint32_t offset, uint8_t value) {
			if (validSection(sectionID)) {
				relFile.seekg(toAddress(sectionInfoTable[sectionID].offset, offset), std::fstream::beg);
				writeBigByte(relFile, value);
			}
		}

		void writeToSection(uint32_t sectionID, uint32_t offset, uint32_t *values, int32_t count) {
			if(validSection(sectionID)) {
				relFile.seekg(toAddress(sectionInfoTable[sectionID].offset, offset), std::fstream::beg);
				for (int32_t i = 0; i < count; i++) {
					writeBigInt(relFile, values[i]);
				}
			}
		}

		void writeToSection(uint32_t sectionID, uint32_t offset, uint16_t *values, int32_t count) {
			if (validSection(sectionID)) {
				relFile.seekg(toAddress(sectionInfoTable[sectionID].offset, offset), std::fstream::beg);
				for (int32_t i = 0; i < count; i++) {
					writeBigShort(relFile, values[i]);
				}
			}
		}

		void writeToSection(uint32_t sectionID, uint32_t offset, uint8_t *values, int32_t count) {
			if (validSection(sectionID)) {
				relFile.seekg(toAddress(sectionInfoTable[sectionID].offset, offset), std::fstream::beg);
				for (int32_t i = 0; i < count; i++) {
					writeBigByte(relFile, values[i]);
				}
			}
		}

	private:

		uint32_t toAddress(uint32_t raw) {
			return raw & ((~0) ^ 0x1);
		}

		std::streamoff toAddress(uint32_t raw, uint32_t offset) {
			return (std::streamoff) ((raw & ((~0) ^ 0x1)) + offset);
		}

		bool validSection(uint32_t sectionID) {
			if (sectionID >= 0 && sectionID < header->sectionCount && sectionInfoTable[sectionID].offset != 0) {
				return true;
			}
			return false;<commit_msg>Added methods to write values at an offset. Made to limit code redundancy a bit (since multiple methods will need to write multiple values at once)<commit_after>#pragma once
#include <fstream>
#include <iostream>
#include <memory>
#include "structs.h"
#include "fileFunctions.h"
#include <string>

namespace RELPatch {

	class RELFile {
	public:

	private:
		std::unique_ptr<Header> header;
		std::unique_ptr<SectionInfoTable[]> sectionInfoTable;
		std::unique_ptr<ImportTable[]> importTable;
		std::fstream relFile;

	public:
		RELFile(char *filename) {
			relFile.open(filename, std::ios::binary | std::ios::in | std::ios::out);
			if (relFile.is_open()) {
				parseRel();
			}
		}

		RELFile(std::string filename) {
			relFile.open(filename, std::ios::binary | std::ios::in | std::ios::out);
			if (relFile.is_open()) {
				parseRel();
			}
		}

		~RELFile() {
			if (relFile.is_open()) {
				relFile.close();
			}
		}

		void writeToSection(uint32_t sectionID, uint32_t offset, uint32_t value) {
			if (validSection(sectionID)) {
				relFile.seekg(toAddress(sectionInfoTable[sectionID].offset, offset), std::fstream::beg);
				writeBigInt(relFile, value);
			}
		}

		void writeToSection(uint32_t sectionID, uint32_t offset, uint16_t value) {
			if (validSection(sectionID)) {
				relFile.seekg(toAddress(sectionInfoTable[sectionID].offset, offset), std::fstream::beg);
				writeBigShort(relFile, value);
			}
		}

		void writeToSection(uint32_t sectionID, uint32_t offset, uint8_t value) {
			if (validSection(sectionID)) {
				relFile.seekg(toAddress(sectionInfoTable[sectionID].offset, offset), std::fstream::beg);
				writeBigByte(relFile, value);
			}
		}

		void writeToSection(uint32_t sectionID, uint32_t offset, uint32_t *values, int32_t count) {
			if(validSection(sectionID)) {
				write(toAddress(sectionInfoTable[sectionID].offset, offset), values, count);
			}
		}

		void writeToSection(uint32_t sectionID, uint32_t offset, uint16_t *values, int32_t count) {
			if (validSection(sectionID)) {
				write(toAddress(sectionInfoTable[sectionID].offset, offset), values, count);
			}
		}

		void writeToSection(uint32_t sectionID, uint32_t offset, uint8_t *values, int32_t count) {
			if(validSection(sectionID)) {
				write(toAddress(sectionInfoTable[sectionID].offset, offset), values, count);
			}
		}

	private:

		uint32_t toAddress(uint32_t raw) {
			return raw & ((~0) ^ 0x1);
		}

		std::streamoff toAddress(uint32_t raw, uint32_t offset) {
			return (std::streamoff) ((raw & ((~0) ^ 0x1)) + offset);
		}

		bool validSection(uint32_t sectionID) {
			if (sectionID >= 0 && sectionID < header->sectionCount && sectionInfoTable[sectionID].offset != 0) {
				return true;
			}
			return false;
		}

		void write(std::streamoff offset, uint32_t *values, int32_t count) {
			relFile.seekg(offset, std::fstream::beg);
			for (int32_t i = 0; i < count; i++) {
				writeBigInt(relFile, values[i]);
			}
		}

		void write(std::streamoff offset, uint16_t *values, int32_t count) {
			relFile.seekg(offset, std::fstream::beg);
			for (int32_t i = 0; i < count; i++) {
				writeBigShort(relFile, values[i]);
			}
		}

		void write(std::streamoff offset, uint8_t *values, int32_t count) {
			relFile.seekg(offset, std::fstream::beg);
			for (int32_t i = 0; i < count; i++) {
				writeBigByte(relFile, values[i]);
			}
{'fraction_non_alphanumeric': 0.14398581102870042, 'fraction_numerical': 0.023379554982263785, 'mean_word_length': 4.484526967285588, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2608866', 'n_tokens_mistral': 2610, 'n_tokens_neox': 2188, 'n_words': 441}