YaLTeR / BunnymodXT

Speedrun and TAS tool for Half-Life & friends.
Other
199 stars 37 forks source link

feature: concept of expanding origin limit for temp entities #503

Open SmileyAG opened 6 months ago

SmileyAG commented 6 months ago

Related to big map PR: https://github.com/YaLTeR/BunnymodXT/pull/500

Well, @khanghugo asked about expanding the origin limit for temp entities, and in general I have a concept of how this can be implemented:

if (msg_type == SVC_TEMPENTITY) { if (is_big_map) msg_svc_tempentity_intercepted = true; }

ORIG_PF_MessageBegin_I(msg_dest, msg_type, pOrigin, ed);

- **PF_WriteCoord_I**: if we have tracked the desired message, redirect it to **PF_WriteLong_I**

```cpp
if (ServerDLL::GetInstance().pEngfuncs)
{
    if (msg_svc_tempentity_intercepted)
    {
        ServerDLL::GetInstance().pEngfuncs->pfnWriteLong(static_cast<int>(flValue));
        return;
    }
}

ORIG_PF_WriteCoord_I(flValue);

HOOK_DEF_0(HwDLL, void, __cdecl, PF_MessageEnd_I) { ResetTrackedMessages(); ORIG_PF_MessageEnd_I(); }


- **CL_ParseTEnt**: track state if inside of function

```cpp
HOOK_DEF_0(HwDLL, void, __cdecl, CL_ParseTEnt)
{
  inside_CL_ParseTEnt = true;
  ORIG_CL_ParseTEnt();
  inside_CL_ParseTEnt = false;
}
if (is_big_map)
{
    if (inside_CL_ParseTEnt && ORIG_MSG_ReadLong)
        return static_cast<float>(ORIG_MSG_ReadLong());
}

The engine also has a function PF_StaticDecal which sent coordinates via MSG_WriteCoord, so it may also need to be replaced there with MSG_WriteLong

Perhaps there are some other temp entities in the engine that are sent via MSG_WriteCoord, I don’t seem to have found them, but I also didn’t look deeply enough

khanghugo commented 6 months ago

Personally I only do stuffs for movement maps so I won't have much use of this. However, when it comes to servers running big maps, this might be very needed. This idea will work nicely in other projects like ReHLDS. I can try implementing this and see. I can use BXT to test my implementation before getting it into something different.

khanghugo commented 6 months ago

Oh wow, after that comment it instantly came to me that it won't work in servers because clients need to decode the messages too. Woop woop.

SmileyAG commented 6 months ago

Oh wow, after that comment it instantly came to me that it won't work in servers because clients need to decode the messages too. Woop woop.

In fact, these limits for temp entities can be expanded without engine changes, but then you must have access to change the code of both client and server sides

In simple words, expanding these limits for example for AG is not impossible, because you can make requests regarding these changes for the client (OpenAG, BHL-Rebased) and server (Adrenaline Gamer 6.7) sides

Here is the full guide on this topic: https://twhl.info/wiki/page/Tutorial%3A_Going_beyond_8192_units%3A_Part_2 But I will briefly outline to you what is generally required for these changes:

Server

Client

Also, in the file common/const.h from HLSDK there is documentation on how to parse each type of temp entity, which will greatly help you with your own implementation on the client side: https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/common/const.h#L121

And yes, the code of these temp entities is quite implementable, since they also rely on the use of an engine interface that is transmitted to the client

For example, if in CL_ParseTEnt function for the TE_KILLBEAM case code used (*efx.R_BeamKill)(iVar15); Then in the client code this can be implemented as gEngfuncs.pEfxAPI->R_BeamKill(iVar15);

TLDR: