Added basic file encryption to writeFile and readFile; Minor changes

This commit is contained in:
Grayson Riffe (Laptop) 2021-08-26 13:17:29 -05:00
parent d74f808a17
commit bc5c17ebfb
15 changed files with 26 additions and 29545 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
.vs/ .vs/
bin/ bin/
int/ int/
dep/
*aps *aps
*res *res

View File

@ -12,8 +12,7 @@ void MainState::onEnter() {
void MainState::update(double deltaTime) { void MainState::update(double deltaTime) {
} }
void MainState::render() { void MainState::render(nf::Renderer& renderer) {
static nf::Renderer& renderer = *m_app->getRenderer();
} }
void MainState::onExit() { void MainState::onExit() {

View File

@ -8,7 +8,7 @@ public:
void onEnter() override; void onEnter() override;
void update(double deltaTime) override; void update(double deltaTime) override;
void render() override; void render(nf::Renderer& renderer) override;
void onExit() override; void onExit() override;
private: private:

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -1,8 +1,6 @@
#include "Application.h" #include "Application.h"
#include <thread> #include <thread>
#include "GL\glew.h"
#include "GL\wglew.h"
#include "Utility.h" #include "Utility.h"
@ -197,7 +195,7 @@ namespace nf {
while (m_running) { while (m_running) {
start_time = std::chrono::steady_clock::now(); start_time = std::chrono::steady_clock::now();
m_currentState->update(m_deltaTime); m_currentState->update(m_deltaTime);
m_currentState->render(); m_currentState->render(*m_renderer);
m_renderer->doFrame(); m_renderer->doFrame();
m_frames++; m_frames++;
if (m_stateChange) if (m_stateChange)
@ -205,11 +203,10 @@ namespace nf {
m_fpsClock2 = std::chrono::steady_clock::now(); m_fpsClock2 = std::chrono::steady_clock::now();
m_fpsDuration = m_fpsClock2 - m_fpsClock1; m_fpsDuration = m_fpsClock2 - m_fpsClock1;
if (m_fpsDuration.count() >= 1.0) { if (m_fpsDuration.count() >= 1.0) {
m_FPS = m_frames; m_FPS = m_frames - 1;
m_frames = 0; m_frames = 0;
Log("FPS: " + std::to_string(m_FPS)); Log("FPS: " + std::to_string(m_FPS));
m_fpsClock1 = std::chrono::steady_clock::now(); m_fpsClock1 = std::chrono::steady_clock::now();
//TODO: Rework calculating FPS
} }
std::this_thread::sleep_until(next_time); std::this_thread::sleep_until(next_time);
m_deltaTime = (double)(std::chrono::steady_clock::now() - start_time).count(); m_deltaTime = (double)(std::chrono::steady_clock::now() - start_time).count();

View File

@ -16,7 +16,7 @@ namespace nf {
} }
void Gamestate::render() { void Gamestate::render(Renderer& renderer) {
} }

View File

@ -23,7 +23,7 @@ namespace nf {
m_counter++; m_counter++;
} }
void IntroGamestate::render() { void IntroGamestate::render(Renderer& renderer) {
} }
void IntroGamestate::onExit() { void IntroGamestate::onExit() {

View File

@ -81,8 +81,8 @@ namespace nf {
MultiByteToWideChar(CP_ACP, NULL, cstr, -1, out, length); MultiByteToWideChar(CP_ACP, NULL, cstr, -1, out, length);
return out; return out;
} }
//TODO: File encryption
bool writeFile(const char* filename, const std::string& in) { bool writeFile(const char* filename, const std::string& in, bool encrypted) {
std::string file(filename); std::string file(filename);
if (file.find('/') != std::string::npos || file.find('\\') != std::string::npos) { if (file.find('/') != std::string::npos || file.find('\\') != std::string::npos) {
int pos = file.find_last_of("/\\"); int pos = file.find_last_of("/\\");
@ -100,19 +100,29 @@ namespace nf {
out.open(filename); out.open(filename);
if (!out) if (!out)
Error("File \"" + (std::string)filename + (std::string)"\" could not be written!"); Error("File \"" + (std::string)filename + (std::string)"\" could not be written!");
out << in; std::string write(in);
if (encrypted) {
for (unsigned int i = 0; i < write.size(); i++)
write[i] = write[i] + 100;
}
out << write;
out.close(); out.close();
return true; return true;
} }
std::string readFile(const char* filename) { std::string readFile(const char* filename, bool encrypted) {
std::ifstream in; std::ifstream in;
in.open(filename); in.open(filename);
if (!in) if (!in)
Error("File \"" + (std::string)filename + (std::string)"\" could not be read!"); Error("File \"" + (std::string)filename + (std::string)"\" could not be read!");
std::stringstream ss; std::stringstream ss;
ss << in.rdbuf(); ss << in.rdbuf();
return ss.str(); std::string read(ss.str());
if (encrypted) {
for (unsigned int i = 0; i < read.size(); i++)
read[i] = read[i] - 100;
}
return read;
} }
} }

View File

@ -13,7 +13,7 @@ namespace nf {
virtual void onEnter(); virtual void onEnter();
virtual void update(double deltaTime); virtual void update(double deltaTime);
virtual void render(); virtual void render(Renderer& renderer);
virtual void onExit(); virtual void onExit();
protected: protected:

View File

@ -9,7 +9,7 @@ namespace nf {
void onEnter() override; void onEnter() override;
void update(double deltaTime) override; void update(double deltaTime) override;
void render() override; void render(Renderer& renderer) override;
void onExit() override; void onExit() override;
private: private:

View File

@ -46,7 +46,7 @@ std::exit(-1);}
const wchar_t* toWide(const char* in); const wchar_t* toWide(const char* in);
const wchar_t* toWide(const std::string& in); const wchar_t* toWide(const std::string& in);
bool writeFile(const char* filename, const std::string& in); bool writeFile(const char* filename, const std::string& in, bool encrypted = false);
std::string readFile(const char* filename); std::string readFile(const char* filename, bool encrypted = false);
} }