From 995cd5e80aa6cf2d2f89e39ba968d6671ed5249b Mon Sep 17 00:00:00 2001 From: "Grayson Riffe (Laptop)" Date: Sun, 29 Aug 2021 01:02:37 -0500 Subject: [PATCH] Wrote the asset pack creator; Encryption no longer needs to be specified in readFile --- .../2. Textured Quad with Transformations.png | Bin 0 -> 10548 bytes Game/Game.vcxproj | 12 ++ NFPackCreator/NFPackCreator.rc | 100 +++++++++++++++ NFPackCreator/NFPackCreator.vcxproj | 98 ++++++++++++++ NFPackCreator/NFPackCreator.vcxproj.filters | 32 +++++ NFPackCreator/NFPackCreator.vcxproj.user | 16 +++ NFPackCreator/resource.h | 14 ++ NFPackCreator/src/main.cpp | 120 ++++++++++++++++++ NothinFancy/src/Assets.cpp | 2 +- NothinFancy/src/Utility.cpp | 23 ++-- NothinFancy/src/include/Utility.h | 4 +- STEMSln.sln | 11 ++ 12 files changed, 418 insertions(+), 14 deletions(-) create mode 100644 DevScreenshots/2. Textured Quad with Transformations.png create mode 100644 NFPackCreator/NFPackCreator.rc create mode 100644 NFPackCreator/NFPackCreator.vcxproj create mode 100644 NFPackCreator/NFPackCreator.vcxproj.filters create mode 100644 NFPackCreator/NFPackCreator.vcxproj.user create mode 100644 NFPackCreator/resource.h create mode 100644 NFPackCreator/src/main.cpp diff --git a/DevScreenshots/2. Textured Quad with Transformations.png b/DevScreenshots/2. Textured Quad with Transformations.png new file mode 100644 index 0000000000000000000000000000000000000000..e651644e827f04ad71bd4068ab52fc83d4aadb36 GIT binary patch literal 10548 zcmeHNcU05KzW;$JxFTR##Z^HTm35IOAVMgLB29{bqLc(hKwvSrfYd-x7i=pQigc7F zQX*2NgkS;bO3+9R3IRe0p#(xm2yX`Oz3-p<_P%rOeSf@j)=kx8~aMRk- zc>NDQ{eU3IdQ+2QHVCp>7(s-m#MXe7*4<*x;E#}>jjdqjN)&Qr%0{h?taL5t)Nm1g zv)V?u^av}%OnU9PkFQKj;`cZ{p!CFDsUDs1D>Kf=Q6{}O0{!$v)Ts6-nu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1@k$bbO%zpW@Gz1HyjXSf%Ft$of8;2H z=mY|gK(@l>jdY_3;N2$BslqA6vz=D0&U;!8=Hq~fg}+fD6K9Oz*fuxV881JILcj- zC-O5CwKXL11ilDC{>8s0eDD4OjQ;Hw(RZA`tJ!~~*Z5tLzAMsqMf!j0kT0HD9PGTS gy9P#-aT~K`*$qKT^WvVSc5uPe$nsc`q080(0u6H#bpQYW literal 0 HcmV?d00001 diff --git a/Game/Game.vcxproj b/Game/Game.vcxproj index de3235c..9059d0b 100644 --- a/Game/Game.vcxproj +++ b/Game/Game.vcxproj @@ -108,6 +108,9 @@ $(ProjectDir)dep\;%(AdditionalLibraryDirectories) nf.res;%(AdditionalDependencies) + + cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && copy "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\" + @@ -131,6 +134,9 @@ $(ProjectDir)dep\;%(AdditionalLibraryDirectories) nf.res;%(AdditionalDependencies) + + cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && copy "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\" + @@ -150,6 +156,9 @@ $(ProjectDir)dep\;%(AdditionalLibraryDirectories) nf.res;%(AdditionalDependencies) + + cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && copy "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\" + @@ -173,6 +182,9 @@ $(ProjectDir)dep\;%(AdditionalLibraryDirectories) nf.res;%(AdditionalDependencies) + + cd "$(SolutionDir)NFPackCreator\bin\AssetBuild" && "$(SolutionDir)NFPackCreator\bin\Win32$(Configuration)\NFPackCreator.exe" && del "$(OutDir)assets\" /Q /S && copy "$(SolutionDir)NFPackCreator\bin\AssetBuild\*.nfpack" "$(OutDir)assets\" + diff --git a/NFPackCreator/NFPackCreator.rc b/NFPackCreator/NFPackCreator.rc new file mode 100644 index 0000000..d44f749 --- /dev/null +++ b/NFPackCreator/NFPackCreator.rc @@ -0,0 +1,100 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,1 + PRODUCTVERSION 1,0,0,1 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "Grayson Riffe" + VALUE "FileDescription", "Nothin' Fancy Asset Pack Creator" + VALUE "FileVersion", "1.0" + VALUE "InternalName", "NFPackCreator.exe" + VALUE "LegalCopyright", "Copyright (C) 2021 Grayson Riffe" + VALUE "OriginalFilename", "NFPackCreator.exe" + VALUE "ProductName", "Nothin' Fancy Asset Pack Creator" + VALUE "ProductVersion", "1.0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/NFPackCreator/NFPackCreator.vcxproj b/NFPackCreator/NFPackCreator.vcxproj new file mode 100644 index 0000000..1959143 --- /dev/null +++ b/NFPackCreator/NFPackCreator.vcxproj @@ -0,0 +1,98 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + 16.0 + Win32Proj + {771b4aee-e2c6-4745-ac40-1ef57149612e} + NFPackCreator + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + true + $(ProjectDir)bin\$(Platform)$(Configuration)\ + $(ProjectDir)int\$(Platform)$(Configuration)\ + + + false + $(ProjectDir)bin\$(Platform)$(Configuration)\ + $(ProjectDir)int\$(Platform)$(Configuration)\ + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp17 + + + Console + true + true + true + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NFPackCreator/NFPackCreator.vcxproj.filters b/NFPackCreator/NFPackCreator.vcxproj.filters new file mode 100644 index 0000000..61fce6a --- /dev/null +++ b/NFPackCreator/NFPackCreator.vcxproj.filters @@ -0,0 +1,32 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;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 + + + + + Resource Files + + + \ No newline at end of file diff --git a/NFPackCreator/NFPackCreator.vcxproj.user b/NFPackCreator/NFPackCreator.vcxproj.user new file mode 100644 index 0000000..5e75a14 --- /dev/null +++ b/NFPackCreator/NFPackCreator.vcxproj.user @@ -0,0 +1,16 @@ + + + + true + + + $(OutDir) + WindowsLocalDebugger + -h + + + $(OutDir) + WindowsLocalDebugger + -h + + \ No newline at end of file diff --git a/NFPackCreator/resource.h b/NFPackCreator/resource.h new file mode 100644 index 0000000..a2d92eb --- /dev/null +++ b/NFPackCreator/resource.h @@ -0,0 +1,14 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by NFPackCreator.rc + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/NFPackCreator/src/main.cpp b/NFPackCreator/src/main.cpp new file mode 100644 index 0000000..ebbed33 --- /dev/null +++ b/NFPackCreator/src/main.cpp @@ -0,0 +1,120 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +void Log(const std::string& in) { + std::cout << "[NFPackCreator] Info: " << in << "\n"; +} + +void Log(const char* in) { + std::cout << "[NFPackCreator] Info: " << in << "\n"; +} + +__declspec(noreturn) void Error(const std::string& in) { + HANDLE cmd = GetStdHandle(STD_OUTPUT_HANDLE); + SetConsoleTextAttribute(cmd, FOREGROUND_RED); + std::cout << "[NFPackCreator] Error: " + in + "\n"; + SetConsoleTextAttribute(cmd, 7); + std::this_thread::sleep_for(std::chrono::seconds(3)); + std::exit(-1); +} + +void Success(const std::string& in) { + HANDLE cmd = GetStdHandle(STD_OUTPUT_HANDLE); + SetConsoleTextAttribute(cmd, FOREGROUND_GREEN); + std::cout << "[NFPackCreator] Success: " + in + "\n"; + SetConsoleTextAttribute(cmd, 7); +} + +std::string readFile(const std::string& filename) { + std::ifstream in; + in.open(filename); + if (!in) + Error("File \"" + (std::string)filename + (std::string)"\" could not be read!"); + std::stringstream ss; + ss << in.rdbuf(); + std::string read(ss.str()); + if (read.size() > 4 && read.substr(0, 4) == "NFEF") { + read = read.substr(4); + for (unsigned int i = 0; i < read.size(); i++) + read[i] = read[i] - 100; + } + return read; +} + +void writeFile(const std::string& filename, const std::string& in, bool encrypted) { + std::ofstream out; + out.open(filename); + if (!out) + Error("File \"" + (std::string)filename + (std::string)"\" could not be written!"); + std::string write(in); + if (encrypted) { + for (unsigned int i = 0; i < write.size(); i++) + write[i] = write[i] + 100; + write.insert(0, "NFEF"); + } + out << write; + out.close(); +} + +int main(int argc, char* argv[]) { + Log("Starting up"); + + if (argc > 1) { + if ((std::string)argv[1] == "-h") { + Log("Nothin' Fancy Asset Pack Creator\nThis tool creates .nfpack files for the NF engine to load at runtime.\nA pack gets created for each directory in the working directory if there are only compatible files inside.\nSubdirectories are not ignored."); + return 0; + } + } + + std::set extensions; + extensions.insert({ "obj", "png" }); + + unsigned int dirCount = 0; + const std::filesystem::path workingDir = std::filesystem::current_path(); + for (const auto& currDir : std::filesystem::directory_iterator(std::filesystem::current_path())) { + if (!currDir.is_directory()) + continue; + std::string filename = currDir.path().filename().string().append(".nfpack"); + Log("Creating pack \"" + filename + (std::string)"\""); + std::ifstream in; + std::stringstream out; + unsigned int fileCount = 0; + for (const auto& curr : std::filesystem::recursive_directory_iterator(currDir)) { + if (curr.is_directory()) + continue; + std::filesystem::path relative = std::filesystem::relative(curr, currDir); + if (extensions.find(relative.extension().string().substr(1)) == extensions.end()) + Error("File \"" + relative.string() + (std::string)"\" is not of supported type!"); + Log("Current file: " + relative.string()); + + in.open(curr.path(), std::ios::binary); + if (!in) + Error("Couldn't open \"" + relative.string() + (std::string)"\"!"); + if (out.rdbuf()->in_avail() != 0) + out << "\n"; + out << "#NFASSET " + curr.path().filename().string(); + out << "\n"; + out << in.rdbuf(); + in.close(); + fileCount++; + } + if (fileCount == 0) { + Log("No files found inside of \"" + currDir.path().filename().string() + (std::string)"\". No pack written."); + continue; + } + writeFile(filename, out.str(), true); + Success("Wrote \"" + filename + (std::string)"\" containing " + std::to_string(fileCount) + (std::string)" files."); + dirCount++; + } + if (dirCount > 0) + Log("Wrote " + std::to_string(dirCount) + (std::string)" asset pack(s)."); + Log("Done"); + std::this_thread::sleep_for(std::chrono::seconds(2)); + return 0; +} \ No newline at end of file diff --git a/NothinFancy/src/Assets.cpp b/NothinFancy/src/Assets.cpp index f06dfef..f7eecba 100644 --- a/NothinFancy/src/Assets.cpp +++ b/NothinFancy/src/Assets.cpp @@ -23,7 +23,7 @@ namespace nf { void AssetPack::load(const char* packName) { std::string path = "assets/" + (std::string)packName + ".nfpack"; - std::string contents = readFile(path.c_str(), true); + std::string contents = readFile(path); } AssetPack::~AssetPack() { diff --git a/NothinFancy/src/Utility.cpp b/NothinFancy/src/Utility.cpp index bc6d6bf..859c525 100644 --- a/NothinFancy/src/Utility.cpp +++ b/NothinFancy/src/Utility.cpp @@ -35,7 +35,7 @@ namespace nf { SetConsoleTextAttribute(cmd, FOREGROUND_RED); std::printf("[%.4f] Error (%s, %i): %s\n", time.count(), filename, line, in); SetConsoleTextAttribute(cmd, 7); - CloseHandle(cmd); + FindClose(cmd); } void Debug::ErrorImp(const std::string& in, const char* filename, int line) { @@ -45,7 +45,7 @@ namespace nf { std::printf("[%.4f] Error (%s, %i): ", time.count(), filename, line); std::cout << in << "\n"; SetConsoleTextAttribute(cmd, 7); - CloseHandle(cmd); + FindClose(cmd); } std::chrono::duration Debug::getCurrentTime() { @@ -82,11 +82,10 @@ namespace nf { return out; } - bool writeFile(const char* filename, const std::string& in, bool encrypted) { - std::string file(filename); - if (file.find('/') != std::string::npos || file.find('\\') != std::string::npos) { - int pos = file.find_last_of("/\\"); - std::string temp = file.substr(0, pos); + void writeFile(const std::string& filename, const std::string& in, bool encrypted) { + if (filename.find('/') != std::string::npos || filename.find('\\') != std::string::npos) { + int pos = filename.find_last_of("/\\"); + std::string temp = filename.substr(0, pos); std::wstring folders(temp.begin(), temp.end()); WCHAR exe[MAX_PATH]; GetModuleFileName(GetModuleHandle(NULL), exe, MAX_PATH); @@ -104,21 +103,23 @@ namespace nf { if (encrypted) { for (unsigned int i = 0; i < write.size(); i++) write[i] = write[i] + 100; + write.insert(0, "NFEF"); } out << write; out.close(); - return true; } - std::string readFile(const char* filename, bool encrypted) { + std::string readFile(const std::string& filename) { std::ifstream in; - in.open(filename); + in.open(filename, std::ios::binary); + //TODO: Test this change if (!in) Error("File \"" + (std::string)filename + (std::string)"\" could not be read!"); std::stringstream ss; ss << in.rdbuf(); std::string read(ss.str()); - if (encrypted) { + if (read.size() > 4 && read.substr(0, 4) == "NFEF" ){ + read = read.substr(4); for (unsigned int i = 0; i < read.size(); i++) read[i] = read[i] - 100; } diff --git a/NothinFancy/src/include/Utility.h b/NothinFancy/src/include/Utility.h index 609e841..66d7d90 100644 --- a/NothinFancy/src/include/Utility.h +++ b/NothinFancy/src/include/Utility.h @@ -46,7 +46,7 @@ std::exit(-1);} const wchar_t* toWide(const char* in); const wchar_t* toWide(const std::string& in); - bool writeFile(const char* filename, const std::string& in, bool encrypted = false); - std::string readFile(const char* filename, bool encrypted = false); + void writeFile(const std::string& filename, const std::string& in, bool encrypted = false); + std::string readFile(const std::string& filename); } \ No newline at end of file diff --git a/STEMSln.sln b/STEMSln.sln index bc4469b..035a62f 100644 --- a/STEMSln.sln +++ b/STEMSln.sln @@ -6,6 +6,11 @@ MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NothinFancy", "NothinFancy\NothinFancy.vcxproj", "{1B9C5361-E301-41BF-97E7-56D65F11E2BB}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Game", "Game\Game.vcxproj", "{B7FEC2D6-1D8F-487E-89CB-FD611FD1AEB6}" + ProjectSection(ProjectDependencies) = postProject + {771B4AEE-E2C6-4745-AC40-1EF57149612E} = {771B4AEE-E2C6-4745-AC40-1EF57149612E} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NFPackCreator", "NFPackCreator\NFPackCreator.vcxproj", "{771B4AEE-E2C6-4745-AC40-1EF57149612E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -27,6 +32,12 @@ Global {B7FEC2D6-1D8F-487E-89CB-FD611FD1AEB6}.Release|x64.ActiveCfg = Release|x64 {B7FEC2D6-1D8F-487E-89CB-FD611FD1AEB6}.Release|x86.ActiveCfg = Release|Win32 {B7FEC2D6-1D8F-487E-89CB-FD611FD1AEB6}.Release|x86.Build.0 = Release|Win32 + {771B4AEE-E2C6-4745-AC40-1EF57149612E}.Debug|x64.ActiveCfg = Debug|Win32 + {771B4AEE-E2C6-4745-AC40-1EF57149612E}.Debug|x86.ActiveCfg = Debug|Win32 + {771B4AEE-E2C6-4745-AC40-1EF57149612E}.Debug|x86.Build.0 = Debug|Win32 + {771B4AEE-E2C6-4745-AC40-1EF57149612E}.Release|x64.ActiveCfg = Release|Win32 + {771B4AEE-E2C6-4745-AC40-1EF57149612E}.Release|x86.ActiveCfg = Release|Win32 + {771B4AEE-E2C6-4745-AC40-1EF57149612E}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE