Skip to content

Commit bdf26f4

Browse files
committed
Remove explicit priorities
1 parent 3423eae commit bdf26f4

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Extract/copy the files into the game folder.
77
Currently the extension only supports 32-bit TF2, but it can in idea work with other games by expanding the gamedata.
88

99
## Usage
10-
The extension works with entity properties, the same that you're used to with the `SetEntProp[Type]` functions, except it doesn't set the entity property itself, but instead modifies the sent value. Since not all properties are networkable, the extension allows you to verify if an entity property is networkable through `HasNetworkableProp`. After you know a property is networkable, you can set its sent value with `SetSendVar`, replace it only if its already going to be sent with `ReplaceSendVar`, or prevent it from being sent with `OmitSendVar`.
10+
The extension works with entity properties, the same that you're used to with the `SetEntProp[Type]` functions, except it doesn't set the entity property itself, but instead modifies the sent value. Since not all properties are networkable, the extension allows you to verify if an entity property is networkable through `HasNetworkableProp`. After you know a property is networkable, you can set its sent value with `SetSendVar`, replace it only if its already going to be sent with `ReplaceSendVar`, or prevent it from being sent with `OmitSendVar`. If a property has multiple edits applied at the same time, then the extension will prioritize edits that use most important action present (`Set` > `Replace` > `Omit`, individual > everyone) and choose the latest amongst those.
1111

1212
`SetSendVar` and `ReplaceSendVar` take a custom value that are stored in a handle. These handles can be created with the `SendVar[Type]` functions, where `Type` is the sent type of the property. All handles are automatically freed at the end of the frame, so you can use `SendVar[Type]` directly in the argument of `[Set/Replace]SendVar` without worry. Some properties go through a conversion function called a proxy that might even change its sent type, so make sure to use the proxy output instead if it exists. The extension provides a few such proxies named `SendProxy[Type]` for convenience.
1313

extension.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ using SharedVariant = std::shared_ptr<Variant>;
9090
struct Edit
9191
{
9292
EditAction action;
93-
int priority;
93+
bool all_clients;
9494
int propindex;
9595
const SendProp* prop;
9696
const SharedVariant variant;
@@ -1033,15 +1033,14 @@ bool IsValidClient(IPluginContext* pContext, int client)
10331033
return true;
10341034
}
10351035

1036-
// void SetSendVar(int entity, int client, const char[] prop, Handle value, int priority = 0)
1036+
// void SetSendVar(int entity, int client, const char[] prop, Handle value)
10371037
cell_t smn_SetSendVar(IPluginContext* pContext, const cell_t* params)
10381038
{
10391039
int entref = params[1];
10401040
int client = params[2];
10411041
char* propname;
10421042
pContext->LocalToString(params[3], &propname);
10431043
Handle_t handle = params[4];
1044-
int priority = params[5];
10451044

10461045
if (client != -1 && !IsValidClient(pContext, client))
10471046
return 0;
@@ -1066,21 +1065,20 @@ cell_t smn_SetSendVar(IPluginContext* pContext, const cell_t* params)
10661065
);
10671066
}
10681067

1069-
SharedEdit edit = std::make_shared<Edit>(Edit{EditAction::SET, priority, info.propindex, info.prop, *variant});
1068+
SharedEdit edit = std::make_shared<Edit>(Edit{EditAction::SET, client == -1, info.propindex, info.prop, *variant});
10701069
AddSendVarEdit(entref, client, edit);
10711070

10721071
return 0;
10731072
}
10741073

1075-
// void ReplaceSendVar(int entity, int client, const char[] prop, Handle value, int priority = 0)
1074+
// void ReplaceSendVar(int entity, int client, const char[] prop, Handle value)
10761075
cell_t smn_ReplaceSendVar(IPluginContext* pContext, const cell_t* params)
10771076
{
10781077
int entref = params[1];
10791078
int client = params[2];
10801079
char* propname;
10811080
pContext->LocalToString(params[3], &propname);
10821081
Handle_t handle = params[4];
1083-
int priority = params[5];
10841082

10851083
if (client != -1 && !IsValidClient(pContext, client))
10861084
return 0;
@@ -1105,20 +1103,19 @@ cell_t smn_ReplaceSendVar(IPluginContext* pContext, const cell_t* params)
11051103
);
11061104
}
11071105

1108-
SharedEdit edit = std::make_shared<Edit>(Edit{EditAction::REPLACE, priority, info.propindex, info.prop, *variant});
1106+
SharedEdit edit = std::make_shared<Edit>(Edit{EditAction::REPLACE, client == -1, info.propindex, info.prop, *variant});
11091107
AddSendVarEdit(entref, client, edit);
11101108

11111109
return 0;
11121110
}
11131111

1114-
// void OmitSendVar(int entity, int client, const char[] prop, int priority = 0)
1112+
// void OmitSendVar(int entity, int client, const char[] prop)
11151113
cell_t smn_OmitSendVar(IPluginContext* pContext, const cell_t* params)
11161114
{
11171115
int entref = params[1];
11181116
int client = params[2];
11191117
char* propname;
11201118
pContext->LocalToString(params[3], &propname);
1121-
int priority = params[4];
11221119

11231120
if (client != -1 && !IsValidClient(pContext, client))
11241121
return 0;
@@ -1127,7 +1124,7 @@ cell_t smn_OmitSendVar(IPluginContext* pContext, const cell_t* params)
11271124
if (!FindEntitySendPropInfo(pContext, entref, propname, &info))
11281125
return 0;
11291126

1130-
SharedEdit edit = std::make_shared<Edit>(Edit{EditAction::OMIT, priority, info.propindex, info.prop, SharedVariant{}});
1127+
SharedEdit edit = std::make_shared<Edit>(Edit{EditAction::OMIT, client == -1, info.propindex, info.prop, SharedVariant{}});
11311128
AddSendVarEdit(entref, client, edit);
11321129

11331130
return 0;
@@ -1329,7 +1326,11 @@ void Hook_SendTable_WritePropList(SendTable* sendtable, void* inputdata, int inp
13291326
edits.begin(),
13301327
edits.end(),
13311328
[](const SharedEdit &a, const SharedEdit &b) {
1332-
return a->propindex < b->propindex || (a->propindex == b->propindex && a->priority > b->priority);
1329+
return (
1330+
(a->propindex < b->propindex) ||
1331+
(a->propindex == b->propindex && a->action < b->action) ||
1332+
(a->propindex == b->propindex && a->action == b->action && a->all_clients < b->all_clients)
1333+
);
13331334
}
13341335
);
13351336
edits.erase(

include/sendvaredit.inc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,8 @@ native Handle SendVarString(const char[] string);
125125
* @param client Player's index. Use -1 to target everyone.
126126
* @param prop Property name.
127127
* @param value Value to set (get handle from SendVar[Type] functions).
128-
* @param priority Priority for this edit.
129128
*/
130-
native void SetSendVar(int entity, int client, const char[] prop, Handle value, int priority = 0)
129+
native void SetSendVar(int entity, int client, const char[] prop, Handle value)
131130

132131
/**
133132
* Replace the networked value of an entity's property next time the client is sent an update.
@@ -136,19 +135,17 @@ native void SetSendVar(int entity, int client, const char[] prop, Handle value,
136135
* @param client Player's index. Use -1 to target everyone.
137136
* @param prop Property name.
138137
* @param value Value to set (get handle from SendVar[Type] functions).
139-
* @param priority Priority for this edit.
140138
*/
141-
native void ReplaceSendVar(int entity, int client, const char[] prop, Handle value, int priority = 0)
139+
native void ReplaceSendVar(int entity, int client, const char[] prop, Handle value)
142140

143141
/**
144142
* Prevents an entity's property from being included next time the client is sent an update.
145143
*
146144
* @param entity Entity/edict index.
147145
* @param client Player's index. Use -1 to target everyone.
148146
* @param prop Property name.
149-
* @param priority Priority for this edit.
150147
*/
151-
native void OmitSendVar(int entity, int client, const char[] prop, int priority = 0)
148+
native void OmitSendVar(int entity, int client, const char[] prop)
152149

153150
public Extension __ext_sendvaredit =
154151
{

smsdk_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/* Basic information exposed publicly */
4141
#define SMEXT_CONF_NAME "SendVarEdit"
4242
#define SMEXT_CONF_DESCRIPTION "Manipulate networked property values per client"
43-
#define SMEXT_CONF_VERSION "1.3.1"
43+
#define SMEXT_CONF_VERSION "1.3.2"
4444
#define SMEXT_CONF_AUTHOR "ILDPRUT"
4545
#define SMEXT_CONF_URL "https://github.com/chrb22/sendvaredit"
4646
#define SMEXT_CONF_LOGTAG "SENDVAREDIT"

0 commit comments

Comments
 (0)