Skip to content

Commit f4977ab

Browse files
fix: EyeAngles can now be properly acquired. Vectors use special created copy allocation function
Co-Authored-By: NULLderef <45497774+0xNULLderef@users.noreply.github.com>
1 parent 7b439e2 commit f4977ab

File tree

4 files changed

+42
-32
lines changed

4 files changed

+42
-32
lines changed

README.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,35 @@ The purpose of this plugin is to patch Portal 2 to make the mod work as well as
1515
Note: While represented in C++, below functions are for Squirrel. `const char*` type is translated to `string` type. `byte`, `short`, and `long` types are translated to `integer` type. `void` types are simply the `function` type in Squirrel. `HSCRIPT` is a VScript script handle which is an entity instance.
1616

1717
```c++
18-
void printlP2MM(int level, bool dev, const char* pMsgFormat); | "Logging for the P2MM VScript. The log message must be passed as a string or it will error."
19-
const char* GetPlayerName(int playerIndex); | "Gets player username by their entity index."
20-
int GetSteamID(int playerIndex); | "Gets the account ID component of player SteamID by the player's entity index."
21-
int UserIDToPlayerIndex(int userid); | "Get the player's entity index by their userid."
22-
bool IsMapValid(const char* map); | "Returns true is the supplied string is a available map to load and run."
23-
int GetDeveloperLevelP2MM(); | "Returns the value of ConVar p2mm_developer."
24-
bool IsDedicatedServer(); | "Returns true if this is a dedicated server."
25-
void InitializeEntity(HSCRIPT ent); | "Initializes, spawns, then activates an entity in the map. Create a entity using CreateByClassname, then use this function on its handle. Note: Not all entities will work even after being initialized with this function."
26-
void SendToChat(const char* msg, int playerIndex); | "Sends a raw message to the chat HUD. Specifying no playerIndex or 0 sends to all players. Supports printing localization strings but those that require formatting can't be formatted."
27-
const char* GetGameMainDir(); | "Returns the current game directory. Ex. portal2"
28-
const char* GetGameRootDir(); | "Returns the current root game directory. Ex. Portal 2"
29-
void CallFirstRunPrompt(); | "Shows the first run prompt if enabled in config.nut."
30-
int GetConVarInt(const char* cvName); | "Get the integer value of a ConVar."
31-
const char* GetConVarString(const char* cvName); | "Get the string value of a ConVar."
32-
void SetConVarInt(const char* cvName, int newValue); | "Set the integer value of a ConVar."
33-
void SetConVarString(const char* cvName, const char* newValue); | "Set the string value of a ConVar."
34-
HSCRIPT PlayerByIndex(int playerIndex); | "Takes the player's entity index and returns the player's script handle."
35-
void RespawnPlayer(int playerIndex); | "Respawn the a player by their entity index."
36-
void SetFlashlightState(int playerIndex, bool enable); | "Set the flashlight for a player on or off."
37-
void ConsolePrint(int playerIndex, const char* msg); | "Print a message to a player's console, unlike printl() which is just the host. Specifying no playerIndex or 0 sends to all players. Supports printing localization strings but those that require formatting can't be formatted."
38-
void ClientPrint(int playerIndex, const char* msg); | "Print a message to the top center position of a player's screen. Specifying no playerIndex or 0 sends to all players. Supports printing localization strings but those that require formatting can't be formatted."
39-
void HudPrint(int playerIndex, const char* msg, Vector(float x, float y, int channel), int effect, float fxTime, Vector RGB1, float alpha1, Vector RGB2, float alpha2, Vector(float fadeinTime, float fadeoutTime, float holdTime));
40-
| "Print a message to the screen based on what the game_text entity does, with many values to set. See Valve Developer Commentary for the game_text entity to see what each field does. Vectors are in place for sets of RGB values. Specifying no playerIndex or 0 sends to all players. Supports printing localization strings but those that require formatting can't be formatted."
41-
int GetMaxPlayers(); | "Return max amount of players that can be in the server."
42-
void ShowScoreboard(int playerIndex, bool bEnable); | "Enable or disable displaying the score board a player."
43-
void RemovePlayerUI(const int playerIndex, const bool bBanning) | "Display UI for either banning or kicking so host can ban or kick a player. WIP, need to manually open pause menu to see VGUI"
44-
float TraceLineEx(const Vector& vecAbsStart, const Vector& vecAbsEnd, const int mask, const HSCRIPT ignore, const int collisionGroup)
45-
| "Improved version of TraceLine that allows for checking with bit masks and collision groups. Returns a fraction of line where a collision occured, or if in a solid, the amount spent outside the solid."
46-
const Vector& Script_EyeAngles(const int playerIndex) | "Get the eye angles of a player. WIP seems to crash."
18+
void printlP2MM(int level, bool dev, const char* pMsgFormat); | "Logging for the P2MM VScript. The log message must be passed as a string or it will error."
19+
const char* GetPlayerName(int playerIndex); | "Gets player username by their entity index."
20+
int GetSteamID(int playerIndex); | "Gets the account ID component of player SteamID by the player's entity index."
21+
int UserIDToPlayerIndex(int userid); | "Get the player's entity index by their userid."
22+
bool IsMapValid(const char* map); | "Returns true is the supplied string is a available map to load and run."
23+
int GetDeveloperLevelP2MM(); | "Returns the value of ConVar p2mm_developer."
24+
bool IsDedicatedServer(); | "Returns true if this is a dedicated server."
25+
void InitializeEntity(HSCRIPT ent); | "Initializes, spawns, then activates an entity in the map. Create a entity using CreateByClassname, then use this function on its handle. Note: Not all entities will work even after being initialized with this function."
26+
void SendToChat(const char* msg, int playerIndex); | "Sends a raw message to the chat HUD. Specifying no playerIndex or 0 sends to all players. Supports printing localization strings but those that require formatting can't be formatted."
27+
const char* GetGameMainDir(); | "Returns the current game directory. Ex. portal2"
28+
const char* GetGameRootDir(); | "Returns the current root game directory. Ex. Portal 2"
29+
void CallFirstRunPrompt(); | "Shows the first run prompt if enabled in config.nut."
30+
int GetConVarInt(const char* cvName); | "Get the integer value of a ConVar."
31+
const char* GetConVarString(const char* cvName); | "Get the string value of a ConVar."
32+
void SetConVarInt(const char* cvName, int newValue); | "Set the integer value of a ConVar."
33+
void SetConVarString(const char* cvName, const char* newValue); | "Set the string value of a ConVar."
34+
HSCRIPT PlayerByIndex(int playerIndex); | "Takes the player's entity index and returns the player's script handle."
35+
void RespawnPlayer(int playerIndex); | "Respawn the a player by their entity index."
36+
void SetFlashlightState(int playerIndex, bool enable); | "Set the flashlight for a player on or off."
37+
void ConsolePrint(int playerIndex, const char* msg); | "Print a message to a player's console, unlike printl() which is just the host. Specifying no playerIndex or 0 sends to all players. Supports printing localization strings but those that require formatting can't be formatted."
38+
void ClientPrint(int playerIndex, const char* msg); | "Print a message to the top center position of a player's screen. Specifying no playerIndex or 0 sends to all players. Supports printing localization strings but those that require formatting can't be formatted."
39+
void HudPrint(int playerIndex, const char* msg, Vector(float x, float y, int channel), int effect, float fxTime, Vector RGB1, float alpha1, Vector RGB2, float alpha2, Vector(float fadeinTime, float fadeoutTime, float holdTime));
40+
| "Print a message to the screen based on what the game_text entity does, with many values to set. See Valve Developer Commentary for the game_text entity to see what each field does. Vectors are in place for sets of RGB values. Specifying no playerIndex or 0 sends to all players. Supports printing localization strings but those that require formatting can't be formatted."
41+
int GetMaxPlayers(); | "Return max amount of players that can be in the server."
42+
void ShowScoreboard(int playerIndex, bool bEnable); | "Enable or disable displaying the score board a player."
43+
void RemovePlayerUI(const int playerIndex, const bool bBanning) | "Display UI for either banning or kicking so host can ban or kick a player. WIP, need to manually open pause menu to see VGUI"
44+
float TraceLineEx(const Vector& vecAbsStart, const Vector& vecAbsEnd, const int mask, const HSCRIPT ignore, const int collisionGroup)
45+
| "Improved version of TraceLine that allows for checking with bit masks and collision groups. Returns a fraction of line where a collision occured, or if in a solid, the amount spent outside the solid."
46+
Vector Script_EyeAngles(const int playerIndex) | "Get the eye angles of a player. WIP seems to crash."
4747

4848
```
4949

public/mathlib/vector.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ class Vector
206206
operator VectorByValue &() { return *((VectorByValue *)(this)); }
207207
operator const VectorByValue &() const { return *((const VectorByValue *)(this)); }
208208

209+
// allocate a vector using tier0's memalloc and copy to it from a source vector
210+
static inline Vector* Tier0CopyAlloc(const Vector &vOther)
211+
{
212+
Vector* v = (Vector*)MemAlloc_Alloc(sizeof(Vector));
213+
v->x = vOther.x; v->y = vOther.y; v->z = vOther.z;
214+
return v;
215+
}
216+
209217
#ifndef VECTOR_NO_SLOW_OPERATIONS
210218
// copy constructors
211219
// Vector(const Vector &vOther);

public/vscript/vscript_templates.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ inline FUNCPTR_TYPE ScriptConvertFuncPtrFromVoid( void *p )
320320
} \
321321
*pReturn = ((FUNC_TYPE)pFunction)( SCRIPT_BINDING_ARGS_##N ); \
322322
if ( pReturn->m_type == FIELD_VECTOR ) \
323-
pReturn->m_pVector = new Vector(*pReturn->m_pVector); \
323+
/* new Vector uses the std allocator, this needs tier0 memalloc */ \
324+
pReturn->m_pVector = Vector::Tier0CopyAlloc(*pReturn->m_pVector); \
324325
return true; \
325326
} \
326327
}; \
@@ -360,7 +361,8 @@ inline FUNCPTR_TYPE ScriptConvertFuncPtrFromVoid( void *p )
360361
} \
361362
*pReturn = (((OBJECT_TYPE_PTR)(pContext))->*ScriptConvertFuncPtrFromVoid<FUNC_TYPE>(pFunction))( SCRIPT_BINDING_ARGS_##N ); \
362363
if ( pReturn->m_type == FIELD_VECTOR ) \
363-
pReturn->m_pVector = new Vector(*pReturn->m_pVector); \
364+
/* new Vector uses the std allocator, this needs tier0 memalloc */ \
365+
pReturn->m_pVector = Vector::Tier0CopyAlloc(*pReturn->m_pVector); \
364366
return true; \
365367
} \
366368
}; \

vscript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static float Script_UTIL_TraceLine(const Vector& vecAbsStart, const Vector& vecA
321321
* @param playerIndex Player index to get angles of.
322322
* @return Vector of player eye angles.
323323
*/
324-
static const Vector& Script_EyeAngles(const int playerIndex)
324+
static Vector Script_EyeAngles(const int playerIndex)
325325
{
326326
const QAngle eyeAngles = CBasePlayer__EyeAngles(playerIndex);
327327
return Vector(eyeAngles.x, eyeAngles.y, eyeAngles.z);

0 commit comments

Comments
 (0)