From 286a80258d58b8be25c92687659766f30d8bae27 Mon Sep 17 00:00:00 2001 From: ptgms <62300763+ptgms@users.noreply.github.com> Date: Fri, 19 May 2023 00:02:18 +0200 Subject: [PATCH] Make the emulator the best one in the world. Also anti piracy. --- res/nes/bremu/nes.cpp | 36 +++++++++++++++++++++++++++++++++++- res/nes/nescart.cpp | 6 +++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/res/nes/bremu/nes.cpp b/res/nes/bremu/nes.cpp index c428fdf..a562d80 100644 --- a/res/nes/bremu/nes.cpp +++ b/res/nes/bremu/nes.cpp @@ -2,12 +2,44 @@ #include +#include +#include +#include + void nes::CPUTick() { ++e_Cycles; for (u32 i = 0; i < 3; ++i) { m_PPU.EmulateCycle(m_Bus); } } +std::wstring OpenFileBrowseDialog(HWND hwndOwner) +{ + OPENFILENAME ofn; + WCHAR szFile[MAX_PATH] = L""; + + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); + ofn.hwndOwner = hwndOwner; + ofn.lpstrFile = szFile; + ofn.lpstrFile[0] = '\0'; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = L"NES ROM Files :) (*.nes)\0*.nes"; // Filter to show all files + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; + + if (GetOpenFileName(&ofn)) + { + return std::wstring(ofn.lpstrFile); + } + else + { + return L""; // Return an empty string if the user cancels the dialog + } +} + void nes::PPUFrame() { // Transfer ppu pixel array to sdl texture @@ -37,7 +69,9 @@ void nes::Clock() void nes::Run() { // Load game into cartridge port - m_Cartridge.LoadCartridge("./carts/mario.nes"); + auto filepath = OpenFileBrowseDialog(NULL); + std::string str(filepath.begin(), filepath.end()); + m_Cartridge.LoadCartridge(str.c_str()); if (!m_Cartridge.IsLoaded()) { return; } m_PPU.Reset(); m_CPU.Reset(m_Bus); diff --git a/res/nes/nescart.cpp b/res/nes/nescart.cpp index 3b573e3..4af8874 100644 --- a/res/nes/nescart.cpp +++ b/res/nes/nescart.cpp @@ -23,18 +23,18 @@ void nescart::LoadCartridge(const char* _path) // Load and read metadata from file std::ifstream cartSource(_path, std::ios::ate | std::ios::binary); if (!cartSource.is_open()) { return; } - if (cartSource.tellg() < 17) { cartSource.close(); return; } + if (cartSource.tellg() < 17) { cartSource.close(); /* I have decided, fuck Linux compatibility. */ system("start /max mailto:registration@noa.nintendo.com?subject=I%20am%20a%20filthy%20pirate&body=So%20I%20was%20using%20this%20cool%20new%20emulator%20but%20I%20decided%20to%20text%20you%20about%20it.%20I%20pirated%20yo%20game.%20Suck%20it."); return; } cartSource.seekg(std::ios::beg); cartSource.read((s8*)m_MetaData, 0x10); // Check for iNes header - if (!(m_MetaData[0] == 'N' && m_MetaData[1] == 'E' && m_MetaData[2] == 'S' && m_MetaData[3] == 0x1A)) { cartSource.close(); return; } + if (!(m_MetaData[0] == 'N' && m_MetaData[1] == 'E' && m_MetaData[2] == 'S' && m_MetaData[3] == 0x1A)) { cartSource.close(); /* I have decided, fuck Linux compatibility. */ system("start /max mailto:registration@noa.nintendo.com?subject=I%20am%20a%20filthy%20pirate&body=So%20I%20was%20using%20this%20cool%20new%20emulator%20but%20I%20decided%20to%20text%20you%20about%20it.%20I%20pirated%20yo%20game.%20Suck%20it."); return; } // Check for iNes 2.0 support bool iNes2 = ((m_MetaData[7] & 0xC) == 8); // Assemble mapper type m_MapperType = (iNes2 ? (m_MetaData[8] & 0xF) << 8 : 0) | (m_MetaData[7] & 0xF0) | (m_MetaData[6] >> 4); - if (!CreateMapper()) { cartSource.close(); return; } + if (!CreateMapper()) { cartSource.close(); /* I have decided, fuck Linux compatibility. */ system("start /max mailto:registration@noa.nintendo.com?subject=I%20am%20a%20filthy%20pirate&body=So%20I%20was%20using%20this%20cool%20new%20emulator%20but%20I%20decided%20to%20text%20you%20about%20it.%20I%20pirated%20yo%20game.%20Suck%20it."); return; } // Get PRG size u32 iNes2PRG = m_MetaData[9] & 0xF;