Skip to content

Fixed race on xigncode#16

Merged
kis1yi merged 1 commit into
Silkroad-Developer-Community:mainfrom
kis1yi:xign
Jun 9, 2026
Merged

Fixed race on xigncode#16
kis1yi merged 1 commit into
Silkroad-Developer-Community:mainfrom
kis1yi:xign

Conversation

@kis1yi

@kis1yi kis1yi commented Jun 9, 2026

Copy link
Copy Markdown
Member

thanks to e1N

Summary by CodeRabbit

  • Bug Fixes
    • Improved client startup error handling with clearer feedback when elevated permissions are required.
    • Enhanced initialization process for certain game client versions to ensure proper resource loading before gameplay begins.
    • Increased reliability of the client launch sequence across different regional versions.

thanks to e1N
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR refactors the special-client startup sequence in ClientManager.Start() to handle XIGNCODE-protected executables more robustly. It adds permission error reporting for file operations and introduces type-specific thread control strategies: VTC_Game, Turkey, and Taiwan clients now wait for XIGNCODE unpacking before patching, supported by two new polling helper methods.

Changes

Client Startup Refactoring

Layer / File(s) Summary
Main startup flow refactoring with improved error handling
Library/RSBot.Core/Components/ClientManager.cs
The special-client startup now catches UnauthorizedAccessException when replacing dsound.dll and logs an administrator permission message. Thread control flow branches by client type: VTC_Game, Turkey, and Taiwan wait for the "XIGNCODE\0" marker before patching; other types preserve the earlier fixed resume/sleep/suspend sequence.
Supporting helper methods for dynamic unpacking detection
Library/RSBot.Core/Components/ClientManager.cs
WaitForXigncodeUnpack resumes and re-suspends the main thread in short slices while polling for the XIGNCODE marker with a 5-second timeout, exiting gracefully on process termination. ModuleContains reads the main module into memory and performs byte-sequence scanning, returning false on read failures or exceptions.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 A rabbit hops through unpacked bytes,
Watching XIGNCODE dance in flight—
Thread by thread, we pause and peek,
Till the marker shows what we seek.
With admin rights and helpers true,
The startup flow runs smooth and new! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fixed race on xigncode' directly addresses the main change in the pull request - fixing a race condition in XIGNCODE handling by implementing proper synchronization through the WaitForXigncodeUnpack helper that polls for unpacking completion.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
Library/RSBot.Core/Components/ClientManager.cs (1)

219-220: ⚡ Quick win

Avoid reallocating the full module buffer on every poll.

With the 8 ms slice on Line 219, ModuleContains() currently allocates a fresh module-sized buffer on each iteration. For multi-MB clients, one 5 s wait can churn through hundreds of large allocations in the startup hot path. Reuse a caller-owned buffer and only resize it when ModuleMemorySize changes.

Also applies to: 253-259

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Library/RSBot.Core/Components/ClientManager.cs` around lines 219 - 220, The
polling loop presently allocates a new module-sized buffer every slice (see
sliceMs/maxWaitMs constants) inside ModuleContains(), causing heavy allocation
churn for large ModuleMemorySize values; change ModuleContains and its callers
in ClientManager to accept a caller-owned byte[] buffer (reuseBuffer) that is
allocated once and only resized when ModuleMemorySize changes, pass that buffer
into the read/compare logic instead of creating a new array each iteration, and
apply the same reuse pattern to the other allocation sites referenced around the
253-259 region so the buffer is grown lazily only when ModuleMemorySize
increases.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Library/RSBot.Core/Components/ClientManager.cs`:
- Around line 111-112: Change the logic so WaitForXigncodeUnpack returns an
explicit status (bool or enum) and Start() checks that status before calling
ApplyXigncodePatch; if the unpack wait returned failure (timeout or process
exit) then perform the same abort/cleanup path and return false instead of
proceeding to ApplyXigncodePatch. Update any checks around HasExited/timeout in
the block currently around lines 231-240 to use the new status semantics so
StartClientProcess/GeneralManager.StartClientProcess observes false on failure.
Ensure the unique symbols WaitForXigncodeUnpack, ApplyXigncodePatch, and Start
(or GeneralManager.StartClientProcess caller) are updated to propagate and
handle the returned status consistently.

---

Nitpick comments:
In `@Library/RSBot.Core/Components/ClientManager.cs`:
- Around line 219-220: The polling loop presently allocates a new module-sized
buffer every slice (see sliceMs/maxWaitMs constants) inside ModuleContains(),
causing heavy allocation churn for large ModuleMemorySize values; change
ModuleContains and its callers in ClientManager to accept a caller-owned byte[]
buffer (reuseBuffer) that is allocated once and only resized when
ModuleMemorySize changes, pass that buffer into the read/compare logic instead
of creating a new array each iteration, and apply the same reuse pattern to the
other allocation sites referenced around the 253-259 region so the buffer is
grown lazily only when ModuleMemorySize increases.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ff6cad49-63c7-440b-b06c-1dab4414dfc7

📥 Commits

Reviewing files that changed from the base of the PR and between 57c1328 and dc6d874.

📒 Files selected for processing (1)
  • Library/RSBot.Core/Components/ClientManager.cs

Comment on lines +111 to 112
WaitForXigncodeUnpack(sroProcess, pi.hThread);
ApplyXigncodePatch(sroProcess, pi);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Differentiate unpack success from timeout/exit.

Line 111 treats every return from WaitForXigncodeUnpack() as success, but Lines 231-240 also return on HasExited and timeout. That means Start() can still call ApplyXigncodePatch() on a dead process or fall through the success path even though the XIGNCODE wait failed, which bypasses the false-return contract that GeneralManager.StartClientProcess() is relying on. Return a status from the helper and abort/cleanup on failure instead of patching unconditionally.

Also applies to: 231-240

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Library/RSBot.Core/Components/ClientManager.cs` around lines 111 - 112,
Change the logic so WaitForXigncodeUnpack returns an explicit status (bool or
enum) and Start() checks that status before calling ApplyXigncodePatch; if the
unpack wait returned failure (timeout or process exit) then perform the same
abort/cleanup path and return false instead of proceeding to ApplyXigncodePatch.
Update any checks around HasExited/timeout in the block currently around lines
231-240 to use the new status semantics so
StartClientProcess/GeneralManager.StartClientProcess observes false on failure.
Ensure the unique symbols WaitForXigncodeUnpack, ApplyXigncodePatch, and Start
(or GeneralManager.StartClientProcess caller) are updated to propagate and
handle the returned status consistently.

@kis1yi kis1yi merged commit dbfd590 into Silkroad-Developer-Community:main Jun 9, 2026
2 checks passed
@kis1yi kis1yi deleted the xign branch June 9, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant