Skip to content

Maniac Patch: self-variables, scoped modes 5/6, BreakLoop fix, negative IDs in messages#3546

Closed
luadebug wants to merge 4 commits into
EasyRPG:masterfrom
luadebug:maniac-fixes
Closed

Maniac Patch: self-variables, scoped modes 5/6, BreakLoop fix, negative IDs in messages#3546
luadebug wants to merge 4 commits into
EasyRPG:masterfrom
luadebug:maniac-fixes

Conversation

@luadebug
Copy link
Copy Markdown

Summary

Four fixes for Maniac Patch behaviour, discovered while running SOLDIERS -DesireWing- (RPG Maker 2003 + Maniac Patch). The game uses all four features heavily in its Baton formation menu.

1. Self-variables (negative variable IDs -1..-64)

Maniac Patch defines variable IDs -1 through -64 as "self-variables" — per-context scratch storage separate from the global variable table. Adds a _self_vars[64] array to Game_Variables with Get() and SetOp() support for negative IDs, and suppresses spurious out-of-range warnings for valid negative IDs in ShouldWarn().

2. Scoped variable modes 5 and 6 in DecodeTargetEvaluationMode

Mode 5 (ScopedSingle) and mode 6 (ScopedRange) address self-variables by a 1-based positive index in com.parameters[1] that maps to a negative ID: params[1] = 1 → variable ID -1, etc. These modes were silently falling through to the default: branch (id_0 = 0).

3. BreakLoop — find actual enclosing loop by scanning backward

The previous Maniac Patch path used SkipToNextConditional({EndLoop}, indent - 1), which breaks when BreakLoop is nested inside conditionals within a loop. Example: BreakLoop at indent 3 (inside two levels of if inside an infinite loop at indent 0) was using indent - 1 = 2 to search for EndLoop, finding the wrong target.

Fix: scan backward from BreakLoop to find the innermost enclosing Loop command (tracking EndLoop/Loop pairs to skip already-closed nested loops), then scan forward to its EndLoop. The vanilla RPG_RT bug-emulation path is unchanged.

4. ParseParam: support \v[-N] negative variable IDs in message escape sequences

ParseParam() treated a leading - inside brackets as a non-digit, setting stop_parsing = true and returning 0. Adds an is_negative flag that consumes the - before the digit loop and negates the parsed value at the end. Affects all escape sequences that call ParseParam: \v[N], \t[N], \c[N], \s[N], \n[N].

References

Test case

Game: SOLDIERS -DesireWing- (RPG Maker 2003 + Maniac Patch)

  • Baton formation menu (CE 219) uses \v[-1] in ShowStringPicture to display character SPD from self-variables → previously always showed 0
  • Cancel key exit from the menu uses BreakLoop at indent 2 inside a ConditionalBranch at indent 1 inside an infinite loop at indent 0 → previously could not exit the menu

luadebug and others added 4 commits May 17, 2026 17:22
RPG Maker games using the Maniac Patch can use negative variable IDs
(-1 to -64) as "self-variables" — per-context scratch storage that
doesn't pollute the global variable table.

Add a 64-element `_self_vars` array to Game_Variables. Get() returns
from this array for IDs in [-64..-1], SetOp() writes to it, and
ShouldWarn() suppresses spurious out-of-range warnings for valid
negative IDs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…Mode

Mode 5 (ScopedSingle) and mode 6 (ScopedRange) address self-variables
by a 1-based positive index that maps to negative IDs: params[1]=1
becomes variable ID -1, etc.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The vanilla RPG_RT emulation for BreakLoop unconditionally jumps to the
next EndLoop command in the list, which is correct for vanilla 2003 but
wrong under Maniac Patch where BreakLoop can appear inside conditionals
nested within a loop.

Example: BreakLoop at indent=2 (inside an if at indent=1 inside an
infinite loop at indent=0) must break the outer loop, not whatever
inner loop happens to have its EndLoop appear next in the bytecode.

For Maniac Patch, scan backward from the BreakLoop to find the
innermost enclosing Loop command, tracking EndLoop/Loop pairs to handle
already-closed nested loops correctly, then skip forward to its EndLoop.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ParseParam() treats a leading '-' inside brackets as stopping digit
parsing, so \v[-1] was returned as 0 instead of reading self-variable
-1. Add an is_negative flag that consumes the '-' and negates the
parsed value, matching the Maniac Patch behaviour for \v[-N], \t[-N],
\c[-N], etc.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Ghabry
Copy link
Copy Markdown
Member

Ghabry commented May 17, 2026

I will directly tell you that we will not accept a contribution of such a complex feature from an unknown "developer". Especially not one who sends us vibecoded stuff.

Your AI already made something up and wasted our time with the much simpler Set Game Option contribution.

Just looking for 1 minute at it this patch already makes no sense: The scoped variables are per event and not some "negative index global scratch buffer".


I give you a warning because of spamming. Next AI slop contribution is a ban.

@luadebug luadebug deleted the maniac-fixes branch May 17, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants