Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHUDState m_hud_item_state, m_nextState incorrect initialization on new game #1374

Closed
yohjimane opened this issue Jun 24, 2023 · 3 comments · Fixed by #1375
Closed

CHUDState m_hud_item_state, m_nextState incorrect initialization on new game #1374

yohjimane opened this issue Jun 24, 2023 · 3 comments · Fixed by #1375
Labels
Bug The issue in the run-time.

Comments

@yohjimane
Copy link
Contributor

yohjimane commented Jun 24, 2023

Describe the bug
m_hud_item_state and m_nextState initialize with incorrect value eIdle on new game. The value they should initialize with is eHidden.

To Reproduce
Steps to reproduce the behavior:

  1. put breakpoint in CWeapon::OnActiveItem function, on the first line
  2. Load into new game with debugger enabled
  3. On initial load when breakpoint is hit, observe CHUDState m_hud_item_state, m_nextState = 0 eIdle
  4. Switch to a different weapon, observe CHUDState m_hud_item_state, m_nextState = 0 eIdle
  5. Switch to initial weapon again, observe observe CHUDState m_hud_item_state, m_nextState = 3 eHidden

Expected behavior
On initial load, items should have eHidden state. It looks like this logic should work, but it does not.

Screenshots
Initial load state:
image

State after switching to different weapon, and then switching back
image

@yohjimane yohjimane added the Bug The issue in the run-time. label Jun 24, 2023
@yohjimane
Copy link
Contributor Author

yohjimane commented Jun 24, 2023

This doesn't really effect anything in vanilla game + openxray, but in my fork I want to defer some logic under certain conditions until hud items are in eIdle state.

The logic works in every other case, but doesn't work correctly on initial load due to this bug.

@yohjimane
Copy link
Contributor Author

yohjimane commented Jun 24, 2023

Looks like the root cause of the issue is due to wpn_state default value getting overridden in net_Spawn:

bool CWeapon::net_Spawn(CSE_Abstract* DC)
{
    ...
    CSE_Abstract* e = (CSE_Abstract*)(DC);
    CSE_ALifeItemWeapon* E = smart_cast<CSE_ALifeItemWeapon*>(e);
    ...
    SetState(E->wpn_state); // BUG: wpn_state is always 0 on initial load!
    SetNextState(E->wpn_state);
    ...
}

It looks like this wpn_state data comes from packet, and on initial load since there is no packet it is defaulting to 0...

@Xottab-DUTY
Copy link
Member

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The issue in the run-time.
Projects
None yet
2 participants