Fix critical bugs and improve code quality in FakeParasiteClass#8
Draft
Fix critical bugs and improve code quality in FakeParasiteClass#8
Conversation
…, null checks, timers, and bitwise operations Co-authored-by: deathreaperz <37824218+deathreaperz@users.noreply.github.com>
…helper methods Co-authored-by: deathreaperz <37824218+deathreaperz@users.noreply.github.com>
…throughout parasite methods Co-authored-by: deathreaperz <37824218+deathreaperz@users.noreply.github.com>
Co-authored-by: deathreaperz <37824218+deathreaperz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix bugs in FakeParasiteClass implementation
Fix critical bugs and improve code quality in FakeParasiteClass
Dec 9, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Addresses multiple crash-inducing bugs and code quality issues in parasite attachment system: missing return values causing undefined behavior, use-after-free access, null pointer dereferences, incorrect timer values causing per-frame damage, and bitwise operations on negative values producing unexpected results.
Critical Fixes
Missing return values -
_Loadand_Savemethods now returnS_OKUse-after-free in
__Grapple_AI- Save references before calling__Uninfect():Null pointer checks - Added guards for
Owner,Victim,weapon, andweaponType->Warheadin__AI(),__Grapple_AI(),__Uninfect(),__Infect(), and__Detach()Damage timer - Changed from
Start(0)toStart(weaponType->ROF)to prevent per-frame damage applicationRandom offset calculation - Simplified buggy bitwise logic:
Code Quality Improvements
Magic numbers extracted - Defined
ParasiteConstantsnamespace for bridge height (410), animation frame count (10), Z-offsets (100), height thresholds (200), and overlay ranges (74-99, 205-230)Duplication eliminated - Added
IsSpecialOverlay()for overlay range checks andResetOwnerMission()for owner reinitialization logic, removing ~40 lines of duplicated codeConsistent validation - Unified null checking pattern across all parasite lifecycle methods
Original prompt
FakeParasiteClass Bug Fixes and Improvements
Overview
This PR addresses multiple bugs, potential crashes, and code quality issues identified in the
FakeParasiteClassimplementation insrc/Ext/Parasite/Body.cppandsrc/Ext/Parasite/Body.h.Critical Bug Fixes
1. Missing Return Values in _Load/_Save Methods
Location:
src/Ext/Parasite/Body.h(lines 64-72)Problem: The
_Loadand_Savemethods have no return statements, causing undefined behavior since they returnHRESULT.Current Code:
Fix: Return
S_OKor implement proper serialization:2. Use-After-Uninfect Bug in __Grapple_AI
Location:
src/Ext/Parasite/Body.cpp(lines 369-382)Problem: After calling
__Uninfect(), the code still accessesthis->Ownerandthis->Victimwhich may be invalidated.Current Code:
Fix: Save owner reference before uninfect and fix the else branch to use the saved victim:
3. Missing Null Check for Warhead in __AI
Location:
src/Ext/Parasite/Body.cpp(line 482)Problem:
weaponType->Warheadis accessed without null check.Current Code:
Fix: Add null check:
4. Damage Timer Never Uses Weapon ROF
Location:
src/Ext/Parasite/Body.cpp(line 479)Problem: Timer always starts at 0 instead of using weapon ROF, causing damage every frame.
Current Code:
Fix: Use weapon's ROF value:
this->DamageDeliveryTimer.Start(weaponType->ROF);5. Random Offset Bitwise Operation Bug
Location:
src/Ext/Parasite/Body.cpp(lines 520-521)Problem: Bitwise AND on negative value gives unexpected results due to two's complement representation.
Current Code:
Fix: Simplify the logic to achieve intended behavior:
Code Quality Improvements
6. Extract Magic Numbers to Named Constants
Location:
src/Ext/Parasite/Body.cppAdd constants at the top of the file or in the header:
Replace all magic numbers throughout the code with these constants.
7. Extract Duplicated Code to Helper Methods
Location:
src/Ext/Parasite/Body.cppCreate helper methods for repeated patterns:
Implementation in Body.cpp: