Skip to content

Commit

Permalink
move FileLoader to ModfileLoader module
Browse files Browse the repository at this point in the history
  • Loading branch information
DubbleClick committed Dec 3, 2023
1 parent 3ddfe0b commit 51a7cad
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 55 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ add_library(gMod SHARED)
file(GLOB SOURCES
"header/*.h"
"source/*.cpp"
"source/*.ixx"
"modules/*.ixx"
${VERSION_RC}
)

Expand Down
36 changes: 0 additions & 36 deletions header/FileLoader.h

This file was deleted.

6 changes: 5 additions & 1 deletion header/TextureClient.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#pragma once

#include "FileLoader.h"
#include "uMod_IDirect3DTexture9.h"
#include <DDSTextureLoader/DDSTextureLoader9.h>
#include <DirectXTex/DirectXTex.h>

extern unsigned int gl_ErrorState;

struct TexEntry {
std::vector<BYTE> data{};
HashType crc_hash = 0; // hash value
std::string ext{};
};
struct TextureFileStruct {
std::vector<BYTE> data{};
HashType crc_hash = 0; // hash value
Expand Down
58 changes: 46 additions & 12 deletions source/FileLoader.cpp → modules/ModfileLoader.ixx
Original file line number Diff line number Diff line change
@@ -1,16 +1,50 @@
#include <Main.h>
#include <regex>
#include <algorithm>
#include <filesystem>
#include "FileLoader.h"
#include "TpfReader.h"

FileLoader::FileLoader(const std::string& fileName)
module;

#include "Main.h"
#include "Defines.h"

export module ModfileLoader;

import <intsafe.h>;
import <vector>;
import <string>;
import <libzippp.h>;
import <regex>;
import <algorithm>;
import <filesystem>;
import ModfileLoader.TpfReader;

export class ModfileLoader {
std::string file_name;
const std::string TPF_PASSWORD{
0x73, 0x2A, 0x63, 0x7D, 0x5F, 0x0A, static_cast<char>(0xA6), static_cast<char>(0xBD),
0x7D, 0x65, 0x7E, 0x67, 0x61, 0x2A, 0x7F, 0x7F,
0x74, 0x61, 0x67, 0x5B, 0x60, 0x70, 0x45, 0x74,
0x5C, 0x22, 0x74, 0x5D, 0x6E, 0x6A, 0x73, 0x41,
0x77, 0x6E, 0x46, 0x47, 0x77, 0x49, 0x0C, 0x4B,
0x46, 0x6F
};

public:
ModfileLoader(const std::string& fileName);

std::vector<TexEntry> GetContents();

private:

std::vector<TexEntry> GetTpfContents();

std::vector<TexEntry> GetFileContents();

void LoadEntries(libzippp::ZipArchive& archive, std::vector<TexEntry>& entries);
};

ModfileLoader::ModfileLoader(const std::string& fileName)
{
file_name = std::filesystem::absolute(fileName).string();
}

std::vector<TexEntry> FileLoader::GetContents()
std::vector<TexEntry> ModfileLoader::GetContents()
{
try {
return file_name.ends_with(".tpf") ? GetTpfContents() : GetFileContents();
Expand All @@ -21,7 +55,7 @@ std::vector<TexEntry> FileLoader::GetContents()
return {};
}

std::vector<TexEntry> FileLoader::GetTpfContents()
std::vector<TexEntry> ModfileLoader::GetTpfContents()
{
std::vector<TexEntry> entries;
auto tpf_reader = TpfReader(file_name);
Expand All @@ -43,7 +77,7 @@ std::vector<TexEntry> FileLoader::GetTpfContents()
return entries;
}

std::vector<TexEntry> FileLoader::GetFileContents()
std::vector<TexEntry> ModfileLoader::GetFileContents()
{
std::vector<TexEntry> entries;

Expand Down Expand Up @@ -131,7 +165,7 @@ void ParseTexmodArchive(std::vector<std::string>& lines, libzippp::ZipArchive& a
}
}

void FileLoader::LoadEntries(libzippp::ZipArchive& archive, std::vector<TexEntry>& entries)
void ModfileLoader::LoadEntries(libzippp::ZipArchive& archive, std::vector<TexEntry>& entries)
{
const auto def_file = archive.getEntry("texmod.def");
if (def_file.isNull() || !def_file.isFile()) {
Expand Down
9 changes: 5 additions & 4 deletions header/TpfReader.h → modules/ModfileLoader_TpfReader.ixx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#pragma once
export module ModfileLoader.TpfReader;

#include <fstream>
#include <vector>
import <string>;
import <fstream>;
import <vector>;

class TpfReader {
export class TpfReader {
public:
TpfReader(const std::string& path)
{
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion source/TextureClient.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Main.h"

import TextureFunction;
import ModfileLoader;

TextureClient::TextureClient(IDirect3DDevice9* device)
{
Expand Down Expand Up @@ -134,7 +135,7 @@ void TextureClient::LoadModsFromFile(const char* source)
// Remove newline character
line.erase(std::ranges::remove(line, '\n').begin(), line.end());

auto file_loader = FileLoader(line);
auto file_loader = ModfileLoader(line);
auto entries = file_loader.GetContents();
if (loaded_size > 1'000'000'000) {
Message("LoadModsFromFile: Loaded %d bytes, aborting!!!\n", loaded_size);
Expand Down

0 comments on commit 51a7cad

Please sign in to comment.