• Welcome to Smashboards, the world's largest Super Smash Brothers community! Over 250,000 Smash Bros. fans from around the world have come to discuss these great games in over 19 million posts!

    You are currently viewing our boards as a visitor. Click here to sign up right now and start on your path in the Smash community!

Project FRAY - Melee Decompilation

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
So, people on the Discord have been aware of this, others like Punkline I've been talking to regarding various things here. Figured I may as well make an official post, since it is Christmas.

This is my attempt at starting to rewrite everything about the game, minus things need for videos, memory cards, items that aren't required by a character, and the debug menu. Items will come back later, but I can't speak for the others until I have meaningful progress on everything else.

You can find the work so far here:
https://github.com/PsiLupan/FRAY

This can also serve as a way for you to understand what functions are doing in ASM when writing mods, as well as providing functions to pull out and link to in a C program like Savestate Savestate has previously documented.
 
Last edited:

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
In the interest of reducing the naming similarities to the original game and causing issues in the future, I've renamed the project on GitHub to "FRAY." The URL will redirect there. I've also made some progress on the game startup and some of the HSD library, have added LiboGC's debug console, and done some refactors to help keep the code as readable as possible for anyone who wants to come onboard.

Additionally, as of Thursday, I'm leaving my current job for a new one that'll hopefully give me more patience, time, and experience for the project. I'll also have a little over a week of downtime (spent mostly on my birthday and DMC5, mind you), so I'll certainly be putting in some work.

I suspect by much sooner than later, there will be some visible progress.
 

TDRR

Smash Journeyman
Joined
Sep 18, 2017
Messages
286
Location
Venezuela
So, this is basically kinda-sorta Open-Source Melee? That's pretty neat.

That and just the idea that someone, someday, may make this more portable, including stuff like a GL renderer, makes me very excited. (Native PC version of Melee? Sign me up!)

EDIT: IMO you should remove the swearing in the commit log, because well, you are linking to it from a family-friendly forum, but that's up to you.
 
Last edited:

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
Have recently been making a push to get to the Title screen. I try to document my progress with issues I run into on GitHub using both Issues and the Project section.

Presently, the game now boots, gets into the Class0_OnLoad (used for the Title), loads the GmTtAll.usd, reads and sets the pointers to the sections needed for the Title screen, then fails to allocate memory for the GObj due to an incomplete function. Bypassing that, the FogLoadDesc will work if hsdAllocMemPiece is replaced with a simple malloc, due to GetMemoryEntry being partially incorrect. Then it of course fails when trying to do InitKindObj and subsequent GObj functions due to the NULL GObj.

It's probably possible to work around most of that with mallocs and reach the next bad function, but I'd like to get GetMemoryEntry working as it attempts to allocate memory side-by-side which would lead to better cache usage.

In any case, extremely close to a working Title menu.

Edit: After doing some workarounds and corrections, I've gotten all the way to Menu_Title_SetupLogos, at which point I ran into an incomplete JObj function which has death spiraled into most of the rendering functions. I spent quite a bit of time on that and primarily have TExp to finish some implementation on in order to progress.
 
Last edited:

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
I don't like bumping my own thread, but feel like it's relevant.

The code now loops in the game state without crashing. It tries to render the Title Screen, but I haven't written one of the functions that sets up a GObj callback that grabs the current CObj and Textures for all the JObj and subsequent render calls. I've checked all the XRefs and I haven't been able to locate where it's set, since it is typically the OnLoad function of a Minor Scene class.

I'm going to take a short break on things and start back on it towards the end of the month, as I have some work initiatives that take priority.
 

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
Just came here to say, "wow". Looking forward to the effects of this a couple years from now.
Thanks for the interest.

And as an update, I found that function call I was missing for the textures. I'd actually written it and didn't realize it, because of it being a different function from the usual.

803910D8 is the common callback.
801A1814 is the one that the Title OnLoad uses.

I've gotta write setupNormalCamera, setupBottomHalfCamera, and setupTopHalfCamera, as well as complete the HSD_CObjGetUpVector function. I'm hopeful after that, I'll see one awful looking Title Screen with the TExp functions being incomplete.

Edit: I wrote setupNormalCamera, as the Title used it. Crashing now in LObjSetupInit because the interest is sometimes being initialized with a non-pointer value and it tries to deref it to check the flags. Cause tbd.
 
Last edited:

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
Just wanted to chime in with an update, since I don't like this project seeming dead. I'm still actively working on it. To share current progress, the game is attempting to render according to Dolphin's FIFO log, which is reading the GPU commands. It's clearly visible that the first set of commands is 1:1 with Melee. However, because Blending does not occur from the TEV unit of the Gamecube, it's currently just a black screen.

In order to implement that, I have to complete the TExp component of HAL's Sysdolphin, which is quite possibly the most complicated piece I've dealt with so far due to the number of different types of TExps. I've worked through most of it, but it is currently experiencing crashes towards one of the last parts of the CompileTExp function.

It's been slow moving, but implementing it means that I have the core game in place to continue work towards gameplay and other core menus.
 

dreamhouse

Smash Cadet
Joined
Apr 25, 2015
Messages
27
Location
West Tennessee
It's funny that you posted this now, I was just fixing to bump this and ask for an update. I've been following your github issue page closely even though it's so advanced I have literally no clue what any of it means lol. Super excited about this project and I've been telling all my friends about it.

Gonna irl kreygasm when we see that title screen for the first time!!
 

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
Without further ado, I present to you, the broken Title Screen.

Seizure Warnings abound. Be sure to watch at 60 FPS via your quality settings, or you won't see half the frames.

https://youtu.be/UIawNVK_rYM

For a summary of how it started working, I fixed an issue with CObj where my Viewport was broken. Then, the Scissor was incorrectly sized and culling the contents of the screen.

It's still broken as **** and crashes from an interrupt running and restoring improperly, leading to a bad dereference. The above is the result of a Dolphin FIFO log recording of 3 frames on a loop.

The URDE folks behind the Metroid Prime reimplementation told me LibOGC's lighting is ****ed, which I'm experiencing, combined with Fog and other issues I'm concerned are caused by it. Because I hate LibOGC's GCC toolchain for the other bugs I've experienced, I may be ditching it at some point in favor of a rewrite with Clang.
 
Last edited:

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
Wanting to treat this posts a bit like a blog an explain the process/developments. I may transition to using a GitHub page to do longer posts with pictures. So here's some recent development.

---

I've been doing a lot of debugging on the FIFO, which is essentially a range of memory where the CPU writes GPU commands that are then pushed to the GPU. Dolphin has a FIFO log, so that I can compare what Melee does to the Title vs. what FRAY is doing. When the single frame render was occurring, I was seeing bad lighting updates, a missing fog update, and completely different TEV changes. Texture objects were being put in place, but not all of them were living and were out of order.

To begin debugging that, I used CPPCheck and some other static analyzers, as well as Clang's own warnings, to debug issues with the code. In doing so, I discovered actual bugs in the HSD Lib, which were present all the way to Killer7's version (Some of which is in the available leaked code, such as TObj). With those fixed, I also caught some issues with for loops not updating properly, unnecessary null checks within for loops, and some other minor issues.

From there, I fixed the lighting updates (turns out I needed to map indexes to Light IDs, as HAL had done), determined the missing fog update was the result of a GX Proc that being in debug mode sets, and have yet to determine the cause of the TEV issues. In the course of these fixes, I got Clang to compile the project completely over devkitPro's GCC, which reduces the file size by about 30KB and showed there was undefined behavior and stack corruption issues occurring that GCC was avoiding by virtue of being a piece of **** compiler.

I began debugging the stack corruption using a stack guard via the flag "-fstack-protector-all," which is available on GCC and Clang. What a stack guard does is at the end of every function, if the stack is improper it'll throw an error message about a stack smash and abort the running program. Using those guards, I could set a breakpoint on the stack_chk_fail function and look at the call stack to see what function failed the check. Once I caught the breakpoint, the stack corruption appeared to be coming from JObjLoad. I didn't see any noticeable side effects from Melee's version, but I changed to a disassembled version from K7 instead of Melee's as it was slightly more succinct. I think it was fixed as a result of the stack corruption I was seeing.

After that, I was looping and eventually crashing from HSD_VIXFBCopyAsync, as the GXRModeObj (which is essentially a one of a set of hardcoded structs in the SDK containing NTSC/PAL screen data), was sometimes returning NULL. I did not determine the cause and began double-checking all of my VI functions against Killer7's version, which lead to me adding some inlined functions back. Killer7's version *is* significantly different in a few ways, which I suspect is again the result of bug fixes.

I also looked into Melee's custom exception handler and determined what was causing Libogc's crash handler to not show. I've addressed it and prior to the following issue, I was actually seeing my stack traces again on the rendered console. Getting my custom exception handler to fully take over would require writing some assembly, which at present I have no interest in as Libogc's does the job just fine. Once FRAY is at a "public release" stage, I will look into doing that as I can print out build date information and know if someone isn't running the latest version when an issue is reported.

---

After all the above fixes and changes, the game is looping and rendering nothing at 60 FPS. According to the FIFO log, it is pushing proper frame data at the beginning of the first object each frame, but it does not go through the rest of the render pipeline. As a result, no fog is set, etc.. This is obviously bad, but given that each frame is now containing non-garbage data in that first object, fixing this should hopefully result in the image persisting and updating every frame. Plus, it hopefully will resolve the case of the missing textures.

At this point, I believe it's likely the GX Procs not running, which may be a manifestation of a separate bug. I'm also experiencing a crash from a function that should never run after the main loop has run for several frames, which I'll also be looking into.

Edit: So, procs are running. Rendering is not. Also the crash is a direct result of the loop that handles when the game should transition to the demo.
 
Last edited:

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
Just wanted to get an end-of-November update out.

I fixed up some TExp functions, but I'm still getting some invalid output. Having a really hard time determining the cause. The XFB also doesn't render anything past frame 1 (except the top bar of the Title Menu sometimes making it to frame 2), which has been an on-going issue.

In the process of fixing up TExp, I intentionally broke it and watched different textures get output, which is how I know something about it is incorrect. This is one such example:

MeleeTitleMenu.png


The typical output with the correct ordering (and still whatever is broken), is the TM showing in black instead of Melee.
 

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
Small bit of progress. TExpSchedule was apparently at issue.

Still working out more related to the TExp functionality, as I've used ASM and I've settled on going back through all of them again. Unfortunately, the strategy of using the FIFO and trying to target missing GX function calls or incorrect ones hasn't been very helpful.

1576129844664.png
 

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312

Happy New Year!

Here's a breakdown of the fixes. Other than TExpSchedule, most of the fixes actually came around in the past 8 hours as I kept fighting to figure out why the alpha channel was always 0.


1. TExpSchedule's decomp form was wrong, and my handwritten version was right, minus one "if" check that I had copypasted. Oops.

2. The TExpSetReg function relies consistently on uninitialized data for part of it. It has no real effect, but it was something I needed to match (at least in terms of several values) to have a matching FIFO log.

3. Turns out most of the missing logo stuff was in part actually because the AObjLoadDesc was returning NULL consistently due to a compiler optimization. As a result, JObj would never have an AObj set. This prevented AObj's call into FObj's InterpretAnim, which subsequently calls into TObj's Update. The result of which is the alpha channel being activated to un-hide the objects.


The screen is still flashing because it's rendered across 3 frames presently. The cause is very likely the object rotation going out of the GX's acceptable range, as it's only rendering the first 7 objects on frame 1. Normally it's 29 objects. This is likely the cause of the GX stall as well, but I've not dug into that.

Edit: Fixed rotation. Was using the current frame in the hermite (helmite, according to the Engrish) spline calculation, which was not correct.
 
Last edited:

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
FRAYRendering.jpg


Felt like I had to post, since I got this result today. Turns out I had some ****ed refcounting going on in JObj due to swapping ref_count and ref_count_individual by mistake. The result is that FRAY now renders the full title screen.

I do not know why "Melee" isn't as highlighted, I've had it happen when I was working though TEV bugs by setting the alpha to 255 manually. So my current assumption is the alpha channel is wrong. However, Melee relies on *undefined behavior* when setting TEV colors as the alpha channel, if not set properly, will use the last 8 bits from a pointer on the stack. This may very well be proof of that bug.

Edit: Animation WIP

 
Last edited:

Punkline

Dr. Frankenstack
Joined
May 15, 2015
Messages
423
Congratulations on getting the title screen working! You’ve made some fantastic progress with this project. It’s exciting to see!

I do not know why "Melee" isn't as highlighted, I've had it happen when I was working though TEV bugs by setting the alpha to 255 manually. So my current assumption is the alpha channel is wrong.
I noticed the Melee title joint has a sibling that displays a blurry glow texture that looks sort of additive. It’s easier to see when you hide one of the two siblings:




The top image is the siblings displayed together, like normal. The other images are the title and the glow displayed separately from one another.
The bug looks a lot like the title displayed without the glow, so maybe something is preventing the glow?


Turns out most of the missing logo stuff was in part actually because the AObjLoadDesc was returning NULL consistently due to a compiler optimization. As a result, JObj would never have an AObj set. This prevented AObj's call into FObj's InterpretAnim, which subsequently calls into TObj's Update. The result of which is the alpha channel being activated to un-hide the objects.
I also noticed that the MObj in this sibling glow joint seems to have an AObj that animates the alpha float.
 
Last edited:

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
Yeah, I actually fixed it. When I was referring to the Alpha being 0, I meant the additional joint. It was a bug in my FObj implementation that was never un-hiding that particular object.

I've rewritten it based on K7, since the decompilation of FObjInterpretAnim wasn't 7 while loops there due to inlining being disabled. Only issue is that it's not animating now, because the Hermite Spline function is never reached.

I did the changes slowly over the Melee version before porting completely, and it happened on what was effectively the first inlined function. So, I've gotta work on it a bit. But my initial changes had "Start" animating properly and not the background.

Now that I've got everything in HSD written besides Shadows, I can fix this and focus on either the CSS or gameplay without working too much on rendering bugs again until I need to finish the Top and Bottom CObj implementations.
 

Ryuker

Smash Lord
Joined
Sep 16, 2003
Messages
1,520
Location
The Hague , Netherlands
Exciting stuff so far. Very interested to see how far this project will go. I can’t read assembly but I can read C# and code games in Unity3D so it‘s interesting to peek inside some of the game code after such a long time ^^

Is your intent to keep it running in dolphin or do you intend to get it to run independent in x64 as well?
 
Last edited:

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
Exciting stuff so far. Very interested to see how far this project will go. I can’t read assembly but I can read C# and code games in Unity3D so it‘s interesting to peek inside some of the game code after such a long time ^^

Is your intent to keep it running in dolphin or do you intend to get it to run independent in x64 as well?
My plan is to have it on console, once I resolve the hang. That includes Wii native for the additional memory.

I'm not personally the most saavy on graphics programming, so supporting it on PC would be a bit harder for me. There's some 1:1-esque functions in OpenGL, but then there's everything involving the TEV.

I have a fork written in C++ that needs to be updated now that Sysdolphin is mostly done, then someone could probably more easily target it.

My last post is a bit outdated but everything renders now except the masking effect in the background that makes it sparkle.
 
Last edited:

CorteX

Smash Cadet
Joined
Jan 25, 2010
Messages
55
Location
Den Haag, The Netherlands
Seeing the mario 64 decompilation turn into a full fledged PC port reminded me of this awesome project again.
Hopefully, one day we can free ourselves of Dolphin's shackles and build our own game without all the input latency and add some custom netcode.

I suck at ppc assembly and gfx related stuff, but if I can help with anything else let me know.
 

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
I don't have a lot of time these days to work on it with multiple projects currently launching for work, but the latest update is:

1. The Title Screen renders completely. No more graphical bugs.
2. After fixing DVD issues and a logic mistake for some GX commands, the game now renders on a Gamecube console - which I tested with a 1.0 Melee disc in the drive and an SD card to boot in via HomeBros.

I've started working on getting the CSS operating, though it's been a few weeks since I last addressed it.

I was also doing some reversing of Bloody Roar: Primal Fury, as it uses HAL Sysdolphin. It also uses GObj, which confirms that GObj is in fact shipped with HSD rather than being Melee-specific. It has line-for-line the same GObj functions, as well as some new ones, though some appear to be duplicates.
 

SinsOfApathy

Smash Journeyman
Joined
Feb 24, 2015
Messages
474
NNID
Psion312
For the time being, I've ceased work on FRAY to focus on a new project.

I'm not going to say what it is, but it's visible on my GitHub and contributions. :)
 
Top Bottom