ValveSoftware / halflife

Half-Life 1 engine based games
Other
3.59k stars 598 forks source link

[HL] Flashlight indicator bug #388

Open Matthaiks opened 11 years ago

Matthaiks commented 11 years ago

Save game with fully recharged and switched off flashlight, quit HL, launch HL, load that saved game and look at the flashlight indicator. It says depleted, but it's recharged if you activate it.

Protocol version 48 Exe version 1.1.2.2/Stdio (valve) Exe build: 12:05:47 Feb 18 2013 (5961)

Processor Information: Vendor: AuthenticAMD Speed: 3214 Mhz 4 logical processors 4 physical processors HyperThreading: Unsupported FCMOV: Supported SSE2: Supported SSE3: Supported SSSE3: Supported SSE4a: Supported SSE41: Unsupported SSE42: Unsupported

Network Information: Network Speed:

Operating System Version: Windows 7 (64 bit) NTFS: Supported Crypto Provider Codes: Supported 311 0x0 0x0 0x0

Video Card: Driver: ATI Radeon HD 5700 Series

DirectX Driver Name:  aticfx32.dll
Driver Version:  9.12.0.0
DirectX Driver Version:  8.17.10.1172
Driver Date: 19 Dec 2012
Desktop Color Depth: 32 bits per pixel
Monitor Refresh Rate: 60 Hz
DirectX Card: ATI Radeon HD 5700 Series
VendorID:  0x1002
DeviceID:  0x68b8
Number of Monitors:  1
Number of Logical Video Cards:  1
No SLI or Crossfire Detected
Primary Display Resolution:  1920 x 1200
Desktop Resolution: 1920 x 1200
Primary Display Size: 26.65" x 16.65"  (31.42" diag)
                                        67.7cm x 42.3cm  (79.8cm diag)
Primary Bus Type Not Detected
Primary VRAM: 1024 MB
Supported MSAA Modes:  2x 4x 8x 
jimbond commented 11 years ago

I can also confirm this on the Mac build

SamVanheer commented 3 years ago

This happens because the server doesn't update the HUD on save game load.

To fix this UpdateClientData needs to send an update.

Add a member bool m_bRestored; to CBasePlayer.

Then before this code: https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/dlls/player.cpp#L3066

Add this:

m_bRestored = true;

Then before this code: https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/dlls/player.cpp#L4069-L4097

Add this:

if (m_bRestored)
{
    //Tell client the flashlight is on
    if (FlashlightIsOn())
    {
        MESSAGE_BEGIN(MSG_ONE, gmsgFlashlight, NULL, pev);
        WRITE_BYTE(1);
        WRITE_BYTE(m_iFlashBattery);
        MESSAGE_END();
    }
}

And before this code: https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/dlls/player.cpp#L4181

Add this:

//Handled anything that needs resetting
m_bRestored = false;

On save game load the server will tell the client that the flashlight is on. This code is designed so any other data that needs resetting can be done inside an if (m_bRestored) check as well.

SamVanheer commented 3 years ago

This needs one more thing to work properly in all cases:

if (m_bRestored)
{
    //Always tell client about battery state
    MESSAGE_BEGIN(MSG_ONE, gmsgFlashBattery, NULL, pev);
    WRITE_BYTE(m_iFlashBattery);
    MESSAGE_END();

    //Tell client the flashlight is on
    if (FlashlightIsOn())
    {
        MESSAGE_BEGIN(MSG_ONE, gmsgFlashlight, NULL, pev);
        WRITE_BYTE(1);
        WRITE_BYTE(m_iFlashBattery);
        MESSAGE_END();
    }
}

Otherwise the battery value will be whatever it was before, zero if the game has just been launched.

Matthaiks commented 7 months ago

25th Anniversary Update

Partially fixed, i.e. it displays as turned off instead of depleted: c1a1d0000