mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Store whether a player is activ in C++
This prevents mods from mutating this value and revealing the map. Part of this commit is written by @phosit.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -541,6 +541,38 @@ CMessage* CMessagePlayerColorChanged::FromJSVal(const ScriptRequest& rq, JS::Han
|
||||
return new CMessagePlayerColorChanged(player);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
JS::Value CMessagePlayerWon::ToJSVal(const ScriptRequest& rq) const
|
||||
{
|
||||
TOJSVAL_SETUP();
|
||||
SET_MSG_PROPERTY(playerId);
|
||||
return JS::ObjectValue(*obj);
|
||||
}
|
||||
|
||||
CMessage* CMessagePlayerWon::FromJSVal(const ScriptRequest& rq, JS::HandleValue val)
|
||||
{
|
||||
FROMJSVAL_SETUP();
|
||||
GET_MSG_PROPERTY(player_id_t, playerId);
|
||||
return new CMessagePlayerWon(playerId);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
JS::Value CMessagePlayerDefeated::ToJSVal(const ScriptRequest& rq) const
|
||||
{
|
||||
TOJSVAL_SETUP();
|
||||
SET_MSG_PROPERTY(playerId);
|
||||
return JS::ObjectValue(*obj);
|
||||
}
|
||||
|
||||
CMessage* CMessagePlayerDefeated::FromJSVal(const ScriptRequest& rq, JS::HandleValue val)
|
||||
{
|
||||
FROMJSVAL_SETUP();
|
||||
GET_MSG_PROPERTY(player_id_t, playerId);
|
||||
return new CMessagePlayerDefeated(playerId);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
CMessage* CMessageFromJSVal(int mtid, const ScriptRequest& rq, JS::HandleValue val)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2023 Wildfire Games.
|
||||
/* Copyright (C) 2024 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -46,6 +46,13 @@ void CComponentTypeScript::Deinit()
|
||||
ScriptFunction::CallVoid(rq, m_Instance, "Deinit");
|
||||
}
|
||||
|
||||
bool CComponentTypeScript::HasMessageHandler(const CMessage& msg, const bool global)
|
||||
{
|
||||
const ScriptRequest rq(m_ScriptInterface);
|
||||
return Script::HasProperty(rq, m_Instance, global ? msg.GetScriptGlobalHandlerName() :
|
||||
msg.GetScriptHandlerName());
|
||||
}
|
||||
|
||||
void CComponentTypeScript::HandleMessage(const CMessage& msg, bool global)
|
||||
{
|
||||
ScriptRequest rq(m_ScriptInterface);
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
|
||||
void Init(const CParamNode& paramNode, entity_id_t ent);
|
||||
void Deinit();
|
||||
bool HasMessageHandler(const CMessage& msg, const bool global);
|
||||
void HandleMessage(const CMessage& msg, bool global);
|
||||
|
||||
void Serialize(ISerializer& serialize);
|
||||
@@ -88,8 +89,7 @@ private:
|
||||
}
|
||||
|
||||
|
||||
#define DEFAULT_SCRIPT_WRAPPER(cname) \
|
||||
static void ClassInit(CComponentManager& UNUSED(componentManager)) { } \
|
||||
#define DEFAULT_SCRIPT_WRAPPER_BASIC(cname) \
|
||||
static IComponent* Allocate(const ScriptInterface& scriptInterface, JS::HandleValue instance) \
|
||||
{ \
|
||||
return new CCmp##cname(scriptInterface, instance); \
|
||||
@@ -111,18 +111,6 @@ private:
|
||||
{ \
|
||||
m_Script.Deinit(); \
|
||||
} \
|
||||
void HandleMessage(const CMessage& msg, bool global) override \
|
||||
{ \
|
||||
m_Script.HandleMessage(msg, global); \
|
||||
} \
|
||||
void Serialize(ISerializer& serialize) override \
|
||||
{ \
|
||||
m_Script.Serialize(serialize); \
|
||||
} \
|
||||
void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize) override \
|
||||
{ \
|
||||
m_Script.Deserialize(paramNode, deserialize, GetEntityId()); \
|
||||
} \
|
||||
JS::Value GetJSInstance() const override \
|
||||
{ \
|
||||
return m_Script.GetInstance(); \
|
||||
@@ -135,4 +123,21 @@ private:
|
||||
CComponentTypeScript m_Script; \
|
||||
public:
|
||||
|
||||
|
||||
#define DEFAULT_SCRIPT_WRAPPER(cname) \
|
||||
static void ClassInit(CComponentManager& UNUSED(componentManager)) { } \
|
||||
void HandleMessage(const CMessage& msg, bool global) override \
|
||||
{ \
|
||||
m_Script.HandleMessage(msg, global); \
|
||||
} \
|
||||
void Serialize(ISerializer& serialize) override \
|
||||
{ \
|
||||
m_Script.Serialize(serialize); \
|
||||
} \
|
||||
void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize) override \
|
||||
{ \
|
||||
m_Script.Deserialize(paramNode, deserialize, GetEntityId()); \
|
||||
} \
|
||||
DEFAULT_SCRIPT_WRAPPER_BASIC(cname)
|
||||
|
||||
#endif // INCLUDED_SCRIPTCOMPONENT
|
||||
|
||||
Reference in New Issue
Block a user