Reverse‐Engineering the MPC Memory Limit Architecture (`MemoryUsageMonitor`) - TheKikGen/MPC-LiveXplore GitHub Wiki

1. Overview

The error message "Not enough memory to perform the command" is triggered when system RAM usage crosses a hardcoded percentage threshold evaluated by the MpcMemoryUsageMonitor class.

  • Monitoring Engine Class: MpcMemoryUsageMonitor (inherits from MemoryUsageMonitor)
  • Core Evaluation Method: MpcMemoryUsageMonitor_checkMemory (0x1A6E464, vtable slot +0x1C)
  • RAM Measurement Function: MpcMemoryUsageMonitor_updateRamUsage (0x1A6DD34)

2. How the Memory Usage Ratio is Calculated

MpcMemoryUsageMonitor_updateRamUsage (0x1A6DD34) reads system metrics from the Linux kernel (/proc/meminfo via sub_24AA2E4).

  • It computes the current RAM usage ratio as a single-precision float (float) between 0.0 (0% RAM used) and 1.0 (100% RAM used).
  • The ratio is stored at offset + 36 (float m_current_ram_percentage) inside the monitor instance.

The engine also tracks 4 memory alarm states (m_alarm_state at offset + 76):

  • State 0: Normal (RAM < 80%)
  • State 1: Warning (RAM >= 80%) -> Broadcasts notification "memory.threshold_reached.usage"
  • State 2: High (RAM >= 85%)
  • State 3: Critical (RAM >= 90%)

3. The Command Admission Thresholds

When an action is initiated, Command_perform (0x1940C44) calls MpcMemoryUsageMonitor_checkMemory(this, 3, 1, 1):

; In MpcMemoryUsageMonitor_checkMemory (0x1A6E464):
0x1a6e4a8: BL MpcMemoryUsageMonitor_updateRamUsage ; Refresh current RAM stats
0x1a6e4b0: VLDR S15, [R0,#0x24]                   ; Load current RAM percentage
...
; Level 1 Check (Commands):
0x1a6e570: VLDR S16, =0.8                          ; Load hardcoded 80% threshold!
0x1a6e574: VCMPE.F32 S15, S16                      ; Compare current RAM vs 0.8
0x1a6e578: VMRS APSR_nzcv, FPSCR
0x1a6e57c: BLT loc_1A6E4D8                         ; If current < 80%, return 1 (SUCCESS)
; If current >= 80%:
0x1a6e528: BL sub_1A6A938                          ; Attempt cache cleanup & garbage collect
0x1a6e53c: BL MpcMemoryUsageMonitor_updateRamUsage ; Re-read RAM percentage
0x1a6e54c: CMP current >= 80%                      ; Still above threshold?
0x1a6e558: If yes -> RETURN 0 (FAILED)             ; Abort! Out of memory error

Hardcoded Floating-Point Constants:

Threshold Level Percentage IEEE-754 Hex Value Virtual Address (IDA) Binary File Offset
Level 1 (Command Check) 80.0% (0.8f) CD CC 4C 3F 0x1A6E6E0 0x159D6E0
Level 2 (Critical Check) 90.0% (0.9f) 66 66 66 3F 0x1A6E6E4 0x159D6E4

4. How to Adjust the Memory Ceiling

There are two distinct ways to modify or disable this behavior:

Option 1: Adjust the Threshold Percentage

Rather than bypassing the check entirely, you can raise the threshold from 80% to 95% or 98%:

  • For 95% (0.95f = 0x3F733333):
    • Write 33 33 73 3F at file offset 0x159D6E0.
  • For 98% (0.98f = 0x3F7AE148):
    • Write 48 E1 7A 3F at file offset 0x159D6E0.

Option 2: Complete Memory Check Bypass (The 1A -> EA patch)

As analyzed in MEMORY_CHECK_BYPASS_ANALYSIS.md:

  • At file offset 0x146FC84