You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extract two helpers to reduce duplication across logGameStart, logPlayerDisconnect, logCRCMismatch, and logGameEnd:
writeAtHeaderOffset: handles the repeated seek → write → restore-position
pattern used to update replay header fields (start time, end time, frame count,
desync flag, disconnect flags)
openStatsLogFile: handles the repeated GetComputerName + path construction + fopen pattern used for debug stats logging (RTS_DEBUG only)
No behavior change. Net reduction of ~70 lines per codebase.
This PR extracts two static helper functions—writeAtHeaderOffset and openStatsLogFile—to eliminate repeated seek/write/restore and GetComputerName/fopen patterns across logGameStart, logPlayerDisconnect, logCRCMismatch, and logGameEnd. The refactoring preserves all existing behavior, including the createDirectory call and fallback-to-user-data-dir logic in logGameStart, and the identical change is applied symmetrically to both the Generals and Zero Hour (GeneralsMD) variants.
Confidence Score: 5/5
Safe to merge — pure refactor with no behavior change and no new issues introduced.
Both helpers are straightforward extractions of well-understood patterns. The fallback path in logGameStart is correctly preserved. logGameEnd now calls writeAtHeaderOffset twice instead of once (one extra size()+seek() round-trip), which is functionally equivalent since the file size doesn't change between header writes. No correctness, security, or data-integrity issues found.
Identical refactoring applied to Zero Hour variant; same correctness assessment
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A([logGameStart]) --> B{m_file valid?}
B -- no --> Z([return])
B -- yes --> C[time → startTime]
C --> D["writeAtHeaderOffset\n(seek → write → seek back)"]
D --> E{RTS_DEBUG AND\nTheNetwork AND\nm_saveStats?}
E -- no --> Z2([return])
E -- yes --> F[createDirectory\nm_baseStatsDir]
F --> G["openStatsLogFile()\nm_baseStatsDir + computerName + .txt"]
G --> H{logFP valid?}
H -- yes --> J[fprintf + fclose]
H -- no --> I["fallback:\nm_baseStatsDir = getPath_UserData()"]
I --> K["openStatsLogFile() retry"]
K --> L{logFP valid?}
L -- no --> Z3([return])
L -- yes --> J
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extract two helpers to reduce duplication across
logGameStart,logPlayerDisconnect,logCRCMismatch, andlogGameEnd:writeAtHeaderOffset: handles the repeated seek → write → restore-positionpattern used to update replay header fields (start time, end time, frame count,
desync flag, disconnect flags)
openStatsLogFile: handles the repeatedGetComputerName+ path construction +fopenpattern used for debug stats logging (RTS_DEBUG only)No behavior change. Net reduction of ~70 lines per codebase.