nfsu / NFS

Is a tool created for rom hacking, it stands for Nintendo File System (Utils) and can quickly read and interpret nds files such as NARC, NCLR, NCGR, etc.
MIT License
24 stars 1 forks source link

How to use this? #1

Closed 0xJes closed 6 years ago

0xJes commented 6 years ago

Hello, i want to make a romhacking tool using this to handle read a writes to the rom file.

I was thinking this is library so i tried to run your example as:

#include "NFS-master/NFS/FileSystem.h"
#include <iostream>

int main()
{
    std::cout << "name: ";
    std::string filename;
    std::cin >> filename;

    Buffer buf = readFile(filename);
    try
    {
        nfs::NDS nds = nfs::NType::readNDS(buf);
    }
    catch (std::exception e)
    {
        printf("%s\n", e.what());
    }
    deleteBuffer(&buf);

    std::cin.clear();
    std::cin.ignore(32767, '\n');
    std::cin.get();
}

using: g++ -o test.exe main.cpp -I C:\Users\***\Desktop\nitrotest\NFS-master\NFS

but got about 72 compile errors, all from "Iterators.h", "TypeStruc.h", "NTypes2.h".

Seeing the source files with qt and all makes me thing this is a tool but you present this repo as a lib, i am so confused, i don't even sure what files i should #include in my code to work with this or if this works with GCC.

note: I don't have Visual Studio installed.

Nielsbishere commented 6 years ago

To add NFS to your project, you can do one of the following: A. Add all source and header files to your project B. Get all header files and link them using the .lib Assuming you did the first; you also have to make sure you are using the right C++ version, since a lot of stuff is using C++14 or higher. The current build still has an issue with Release mode with VS; which means it probably won't compile without disabling optimization. I'm guessing the reason is the frequent use of 'template magic'. If that doesn't fix it, leave a reply and I'll try figuring it out. BTW. sorry for the delayed reply.

0xJes commented 6 years ago

Idk how i forgot to compile the source files 😛, however, i compiled all needed source files (i think) and the error list grow even bigger.

I build with gcc.exe (Rev1, Built by MSYS2 project) 7.3.0

now using g++ -std=c++14 -o test.exe test.cpp NFS/NTypes2.cpp NFS/Bitset.cpp NFS/FileSystem.cpp NFS/Generic.cpp NFS/Patcher.cpp NFS/Timer.cpp "C:\Users\***\Desktop\NFS-master\NFS\API\stbi\stbi_write.c" -I C:\Users\***\Desktop\nitrotest\NFS-master\NFS

The compilation errors -> pastebin

Nielsbishere commented 6 years ago

Do these errors change when you use C++17? Some of the template functions may rely on that. Also; Right now, I'm redoing a big part of NFS. I've found that the current system doesn't compile on every compiler (on msvc it only builds without optimizations (Debug)) and the code base is one big mess.

0xJes commented 6 years ago

Using C++17 configuration fixes 3 compilation errors and adds one error note , the rest of errors does not change.

fixes:

NFS/NTypes2.cpp:23:28: error: 'IsValidType' is not a member of 'nfs::NType'
NFS/FileSystem.cpp:181:29: error: 'IsValidType' is not a member of 'nfs::NType'
NFS/FileSystem.cpp:212:29: error: 'IsValidType' is not a member of 'nfs::NType'

Adds:

NFS/Patcher.cpp:62:26: note: suggested alternative:
In file included from NFS/Timer.h:4:0,
                 from NFS/Patcher.cpp:2:
B:/msys64/mingw64/include/c++/7.3.0/chrono:687:7: note:   'std::chrono::ceil'
       ceil(const time_point<_Clock, _Dur>& __tp)
       ^~~~

To this

NFS/Patcher.cpp:62:26: error: 'ceil' was not declared in this scope
  u32 bitsetLength = (u32)ceil(head->blocks / 4.f);
                          ^~~~
Nielsbishere commented 6 years ago

AFAIK, the NFS-Reloaded branch works with 2015 and 2017, though NFSU doesn't work with x86 yet. I'm fixing some template issues that should also allow g++ to work.

Nielsbishere commented 6 years ago

Update: you can now compile the NFS project through g++, I tested it with the command "reload "MinGW Makefiles"". However, the UI project (NFSU) doesn't build yet, but it looks like you weren't planning on using that anyways. It is in the NFS-Reloaded branch. Tell me if you encounter any problems :+1:

0xJes commented 6 years ago

It builds, with a pair of fixes:

In texture.cpp including <cstring> and adding the std namespace to memcpy(ptr, &k, stride); in line 198

The file ntypes.h includes GenericResource.h which should be genericresource.h

Nielsbishere commented 6 years ago

Good :) I only tested it with MinGW Makefiles and MSVC (on windows), I'll push the fixes. :+1: