Skip to content

reimplement: SHC_3BB0A8C1_0x0047BF20 97.5% | SHC_3BB0A8C1_0x0046BB60 100%#139

Draft
TheRedDaemon wants to merge 6 commits into
mainfrom
reimpl/SHC_3BB0A8C1_0x0047BF20
Draft

reimplement: SHC_3BB0A8C1_0x0047BF20 97.5% | SHC_3BB0A8C1_0x0046BB60 100%#139
TheRedDaemon wants to merge 6 commits into
mainfrom
reimpl/SHC_3BB0A8C1_0x0047BF20

Conversation

@TheRedDaemon

Copy link
Copy Markdown
Contributor

No description provided.

namespace MSS {

typedef uint SoundFlagsAndLoopCount;
typedef int SoundFlagsAndLoopCount;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure it is int? Some & operations naturally produce negative right-hand-sides if an int.

@TheRedDaemon TheRedDaemon Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It increased the matching and actually started producing the binary mask instead of just using a mov to a 16bit register.
But this function is another one of these annoying ones. A lot of branch optimization, gotos.
Always in the hope that there is a when: When we manage to match the function, I will try reverting this change and test around a bit.
If this goes through, all other methods need to be tested again, of course.

@TheRedDaemon TheRedDaemon force-pushed the reimpl/SHC_3BB0A8C1_0x0047BF20 branch from 9cef918 to fb16c10 Compare July 3, 2026 22:00
@TheRedDaemon TheRedDaemon force-pushed the reimpl/SHC_3BB0A8C1_0x0047BF20 branch from fb16c10 to 0e8b248 Compare July 5, 2026 00:59
@TheRedDaemon TheRedDaemon added the help wanted Extra attention is needed label Jul 5, 2026
@TheRedDaemon

Copy link
Copy Markdown
Contributor Author

Main issue:
The second early return is considered a "hot path", based on what I read, and its return resolved in place.
This did not happen in the original, which placed this block at the end of the function. The rest of the body is currently identical.
I assume the structure of the rest of the function might be at fault, at least I currently see nothing that could switch this in the condition itself.
Interestingly, inverting the condition (while breaking other stuff), seems to also switch the part order.

Still I would guess the complexity of the rest of the function might be responsible, but I was unable to find something that keeps the logic and does not break other stuff. It might actually be needed to break matching again in the search for the solution.

@gynt

gynt commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

I think if logic wise it is correct it is fine to merge.

@TheRedDaemon TheRedDaemon changed the title reimplement: SHC_3BB0A8C1_0x0047BF20 register and structure issues reimplement: SHC_3BB0A8C1_0x0047BF20 97.5% | SHC_3BB0A8C1_0x0046BB60 100% Jul 5, 2026
@TheRedDaemon TheRedDaemon added declaration/type change This requires changes to the generated/exported types or definitions. and removed help wanted Extra attention is needed labels Jul 5, 2026
@TheRedDaemon

Copy link
Copy Markdown
Contributor Author

Yeah, I still do not have learned my lesson to not overdo it.
There are over 3000 functions, to hell if one or two hundred of them do not match...
In this case I also do not feel like I can return with anything. The branching is a mess in this function and I can both see this as a sign of either a messy function or the compiler having mangled a lot of the original logic...
I just do not think they would write such a weird mix of a switches and really big if else cases?

Fun fact, I managed to push the body of the early return back by wrapping the condition in an do {} while(false); block and use breaks on the inverted and split early return conditions. However, that messed the rest of the function up. These systems are really fragile.

Anyway, the type of the SoundFlagsAndLoopCount still needs to be changed, since this created also non-structural opcode diffs if not and I also added the SHC_3BB0A8C1_0x0046BB60, because I was testing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

declaration/type change This requires changes to the generated/exported types or definitions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants