Giter Club home page Giter Club logo

sead's Introduction

sead

This is a decompilation of sead, the standard C++ library for first-party Nintendo games.

Unlike the original sead decompilation project, which this repo derives from, this project targets more recent versions of sead.

The objective is to recreate the standard library as accurately as possible, so that interoperability can eventually be achieved by adding support for other platforms and by making it easier to create projects that interact with sead games.

Because sead is statically linked in games (and only in games), acquiring the original sead requires legally owning at least one recent first-party Nintendo game. Picking a game that ships with debugging symbols is strongly recommended:

  • Super Mario Odyssey (version 1.0.0) (buy it here)
  • Splatoon 2 (version <= 3.1.0) (buy it here)
  • Nintendo Labo (the pilot build has symbols, file names and assertions)
  • Any other title that has symbols and uses sead

File names, function names and the file organization come from debugging symbols, assertions and information in all of the aforementioned titles. Nobody except Nintendo has the source code of sead, not even third-party developers.

Note that many names (especially for inlined, templated functions) are just plain guesses.

Modules

For progress, refer to the GitHub project page. Several modules currently fail to build for Switch.

  • audio - Audio
  • basis - Types, asserts, allocation operators
  • codec - Base64, CRC16, CRC32
  • container - Templated container classes
  • controller - Controller
  • devenv - Development environment (debug utilities)
  • filedevice - File IO
  • framework - Framework (game framework, tasks, etc.)
  • geom - Geometry
  • gfx - Graphics
  • heap - Heap (arenas, disposers, different types of heaps)
  • hostio - Host IO (communication with PCs)
  • math - Maths utilities (vector, matrix, etc.)
  • message - libms wrapper
  • mc - Multi-core support
  • prim - Primitives (strings, enums, RTTI, etc.)
  • random - Random number generator
  • resource - Resource (loading, decompressing, etc.)
  • stream - Stream IO
  • thread - Thread utilities (threads, critical sections, message queues, etc.)
  • time - Time utilities

Platform specific source

Platform-specific files are usually placed into a subdirectory that is called:

  • cafe for Wii U
  • ctr for 3DS
  • nin for nnSdk (Switch)

Building

Building this project requires:

  • A C++17 capable compiler (or >= Clang 4.0). While older parts of sead are written in C++03, the newer modules in sead target C++11 (or newer) and recent C++ language or library features make writing C++ more convenient.
  • CMake 3.10+

Configuration

sead can be configured with several compile-time defines:

  • SEAD_DEBUG: enables assertions and HostIO code.

Platforms

  • cafe: Wii U
  • NNSDK: nnSdk (Switch and any platform that is supported by modern nnSdk)

Other platforms (generic Unix, iOS, Android, CTR) are not supported.

Matching hacks

This project sometimes uses small hacks to force particular code to be generated by the compiler. Those have no semantic effects but can help with matching assembly code especially when the hacks are used for functions that are inlined.

  • MATCHING_HACK_NX_CLANG: Hacks for Switch sead, when compiling with Clang.

Contributing

Non-inlined functions

When implementing non-inlined functions, please compare the assembly output against the original function and make it match the original code. At this scale, that is pretty much the only reliable way to ensure accuracy and functional equivalency.

However, given the large number of functions, certain kinds of small differences can be ignored when a function would otherwise be equivalent:

  • Regalloc differences.

  • Instruction reorderings when it is obvious the function is still semantically equivalent (e.g. two add/mov instructions that operate on entirely different registers being reordered)

When ignoring minor differences, add a // NOT_MATCHING: explanation comment and explain what does not match.

Header utilities or inlined functions

For header-only utilities (like container classes), use pilot/debug builds, assertion messages and common sense to try to undo function inlining. For example, if you see the same assertion appear in many functions and the file name is a header file, or if you see identical snippets of code in many different places, chances are that you are dealing with an inlined function. In that case, you should refactor the inlined code into its own function.

Also note that introducing inlined functions is sometimes necessary to get the desired codegen.

If a function is inlined, you should try as hard as possible to make it match perfectly. For inlined functions, it is better to use weird code or small hacks to force a match as differences would otherwise appear in every single function that inlines the non-matching code, which drastically complicates matching other functions. If a hack is used, wrap it inside a #ifdef MATCHING_HACK_{PLATFORM} (see above for a list of defines).

sead's People

Contributors

aboood40091 avatar alexapps99 avatar fruityloops1 avatar h1k421 avatar leoetlino avatar mars2032 avatar monsterdruide1 avatar sanae6 avatar savage13 avatar thegreatb3 avatar thepixelgamer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sead's Issues

thread/Atomic

Note that the name is a guess and based on the fact that several thread classes (SpinLock, ReadWriteLock) use atomic load and store operations.

For simplicity reasons, I will probably use C++11 <atomic> to implement the atomic utilities.

heap/HeapMgr

  • HeapMgr
  • HeapMgr complete (...not trivial at all)
  • FindContainHeapCache

gfx/Camera

  • Camera
  • LookAtCamera
  • DirectCamera
  • OrthoCamera

prim/Function (seadFunction.h)

  • IFunction
    • LambdaFunction<LambdaType>
  • AnyFunction

Details

  • IFunction<PointerToFunction> (not PTMFs)
    • virtual ... invoke(...) (no extra level of indirection)
    • virtual isNoDummy() const

container/PtrArray: PtrArrayImpl

PtrArrayImpl is still missing some implementations of common operations (sorting for example). Might not be worth going for a perfect match; an equivalent version might be good enough

prim/Delegate

  • IDelegate
    • AnyDelegate
    • DelegateBase
  • IDelegate1
    • Delegate1
    • AnyDelegate1
    • DelegateBase
  • IDelegate2
    • Delegate2
    • AnyDelegate2
    • DelegateBase
  • IDelegate1R
    • AnyDelegate1R?
  • IDelegate2R
    • AnyDelegate2R
    • LambdaDelegate2R (wraps a lambda, invoke is a wrapper around lambda's operator())
  • IDelegateR<T> (e.g. IDelegateR<bool>)
    • AnyDelegateR<bool>::UnbindDummy (dummy invoke, dummy clone)
    • LambdaDelegateR<bool> (for lambda functions?)

DelegateBase and derived classes

  • DelegateBase (can derive from IDelegate, IDelegate1 or IDelegate2, and possibly more?)
    • Delegate
    • Delegate2
    • Delegate2RFunc (is this the same as Delegate2R?)

IDelegates

  • IDelegate (non templated)
    • virtual void invoke() (pure virtual) ?
    • virtual IDelegate* clone(Heap*) const (returns nullptr)
    • void operator()()?
  • IDelegate2<A1, A2>
    • virtual void invoke(A1, A2)
    • virtual auto clone(Heap*) const
    • void operator()(A1, A2)
  • probably something similar for IDelegate1

R variants (e.g. IDelegate2R) take an extra template argument (at the end) for the return type.

DelegateBase

  • DelegateBase<Class, PTMF, BaseClass> (example: DelegateBase<FaderTaskBase,void (FaderTaskBase::*)(void),IDelegate>)
    • members: instance, pointer-to-member-function
    • getters/setters?

Delegates

  • Delegate2<Class, A1, A2> : DelegateBase<Class, void (Class:*)(A1, A2), IDelegate2<A1, A2>
    • void invoke(A1, A2) override
    • Delegate2<...> clone() const override
  • probably something similar for Delegate, Delegate1

Delegate1R?

AnyDelegates

AnyDelegate1(Const) is constructible from Delegate1. And possibly more? LambdaDelegate1?


The design for this system is kind of bonkers.

digraph {
IDelegate -> DelegateBase
DelegateBase -> Delegate
DelegateBase -> Delegate1
DelegateBase -> Delegate2RFunc
IDelegate1 -> Delegate1 
IDelegate1 -> DelegateBase
IDelegate2 -> Delegate2
IDelegate2 -> DelegateBase
IDelegate1R
IDelegate2R -> DelegateBase

IFunction -> LambdaFunction
AnyFunction

IDelegate -> AnyDelegate
IDelegate1 -> "AnyDelegate1?"
IDelegate2 -> AnyDelegate2
IDelegate1R -> "AnyDelegate1R?"
IDelegate2R -> "AnyDelegate2R?"

IDelegate2R -> LambdaDelegate2R


"IDelegateR<bool>" -> "AnyDelegateR<bool>::UnbindDummy"
"IDelegateR<bool>" -> "LambdaDelegateR<bool>"
}

mc/WorkerMgr

Requires RingBuffer (#44) and framework (InfLoopChecker) stuff

container/TreeMap

This appears to be an implementation of a red-black tree.

TreeMap (seadTreeMap.h, seadTreeNode.cpp):

  • TreeMapImpl<Key>: TreeMapImpl<SafeString>, TreeMapImpl<TreeMapKeyImpl<T>> with T = u32, Thread*, etc.
  • TreeMapNode<Key>
  • TreeMap<Key, Value>

StrTreeMap (seadStrTreeMap.h):

  • StrTreeMap<N, ValueType>: a special case of TreeMapImpl<SafeString>? N seems to be the maximum length of the string keys.
  • Requires FreeList (#45)

thread/Thread

  • Thread (requires #28 HeapMgr and #29 hostio event listener)
  • Thread::State enum
  • Thread: complete implementation except hio
  • Thread: hio (HostIO)
  • ThreadMgr
  • MainThread

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.