Skip to content

Expressions: Add support for algebra expressions that can replace text.#14515

Open
TryTwo wants to merge 1 commit intodolphin-emu:masterfrom
TryTwo:math_expressions
Open

Expressions: Add support for algebra expressions that can replace text.#14515
TryTwo wants to merge 1 commit intodolphin-emu:masterfrom
TryTwo:math_expressions

Conversation

@TryTwo
Copy link
Copy Markdown
Contributor

@TryTwo TryTwo commented Mar 27, 2026

I added a new Math Expressions class that can do algebra from a text string, then replaces itself with the answer in string format. The idea is to make gecko codes with user-modifiable values easier to modify. This uses the expr.h file, which always processes values as double, then converts it to the desired value.

For example ( Thanks to @SuperSamus ):
{ FPS = 60 }
04111111 { float 1 / FPS }
00222222 000000{ u8 FPS / 60 * 7 - 1 }

The first line is optional and always resolves into variables.

I can adjust the syntax if desired. I also wasn't sure if it should be in its own file, or the Expression.h file (made for breakpoints).

I've also done work on the gecko cheat side of things. It can save/load/work correctly, and saves the expression-style code to the ini, so it can be loaded back into the UI later and adjusted by users.

I was speaking with @iwubcode and wasn't sure if this idea could be leverage later for other mod customizations. I wrote it for this specific use case for now, but shouldn't be hard to extend. If we get a more robust mod system, maybe the gecko code itself can be more hidden with just user-facing options being presented.

Can be tested with this PR (use portable mode): #14518

@iwubcode
Copy link
Copy Markdown
Contributor

I'm still deciding what the best approach is for the new mod system. I was initially thinking expr.h would be perfect but now I'm not so sure. Hard to say if we end up breaking users in the future but there's a lot of directions I am considering.

If this gets merged, I will be curious to see how it is used! Thanks for tackling this @TryTwo .

@SuperSamus
Copy link
Copy Markdown
Contributor

There are potential issues in having the variable included in the cheat code itself:

  • If a code is included in Dolphin, does its usage require a copy of the entire code just so that the variable can be changed? This isn't convenient, plus if a code is updated, the copy will remain the same.
  • Does RetroAchievements whitelisting1 only work with one specific value?

I apologize for critiquing this when I previously gave it a thumbs up.

Footnotes

  1. For high FPS codes, RetroAchievements whitelisting would also mandate that a specific VBI Frequency Override value is forced, otherwise it would be easy to play the game in slow motion. So, I'm talking about hypoteticals.

@TryTwo
Copy link
Copy Markdown
Contributor Author

TryTwo commented Mar 28, 2026

There are potential issues in having the variable included in the cheat code itself:

  • If a code is included in Dolphin, does its usage require a copy of the entire code just so that the variable can be changed? This isn't convenient, plus if a code is updated, the copy will remain the same.

When you change the variable, the code will be edited with an updated variable. There's no copying. Each code is given a new member variable raw_code, so it can hold both the expression and the gecko version that is applied.

  • Does RetroAchievements whitelisting only work with one specific value?

I don't know anything about RA whitelisting. You'd have to explain more. Are you talking about Dolphin options being linked to a gecko code, or just locking everything in the gecko code except for variables? You could probably do that second one, so variables have to affect a code in a defined way.

Looking at it again, it may be better for me to have variables use the ini system key, value pairs. Then the raw code becomes constant and can use the ini key/values.
$code name
var1 = 1
var2 = 2
gecko code with expressions

@iwubcode
Copy link
Copy Markdown
Contributor

This feels like a convenience capability, nothing more and that's why I was ok with it. I see it as being useful to simplify things for end users before a more generic system comes along. So for example a FPS code that used this table would instead just have a variable to tweak.

Full end to end FPS mods like what @SuperSamus wants need a more complex system. Like what I have outlined with the mod system which will have setting interaction, a convenient UI, and the state stored independently from the code itself.

@TryTwo TryTwo force-pushed the math_expressions branch from 41ac5ff to d587fa0 Compare March 28, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants