mirror of
https://github.com/roflmuffin/CounterStrikeSharp.git
synced 2025-12-08 17:07:20 -08:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
877b7c5a4a | ||
|
|
24363d6352 | ||
|
|
2eaf7c2d8c | ||
|
|
8b486ecf7e | ||
|
|
54cc93e0f8 | ||
|
|
a695eec4fa | ||
|
|
e207be2fbf |
@@ -56,8 +56,6 @@ set(SOURCE_FILES
|
||||
src/core/tick_scheduler.cpp
|
||||
src/scripting/autonative.h
|
||||
src/scripting/natives/natives_engine.cpp
|
||||
src/core/engine_trace.h
|
||||
src/core/engine_trace.cpp
|
||||
src/scripting/natives/natives_callbacks.cpp
|
||||
src/core/managers/player_manager.h
|
||||
src/core/managers/player_manager.cpp
|
||||
|
||||
@@ -79,7 +79,7 @@ public class HelloWorldPlugin : BasePlugin
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
[ConsoleCommand("issue_warning", "Issue warning to player")]
|
||||
[ConsoleCommand("css_issue_warning", "Issue warning to player")]
|
||||
public void OnCommand(CCSPlayerController? player, CommandInfo command)
|
||||
{
|
||||
Logger.LogWarning("Player shouldn't be doing that");
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
"signatures": {
|
||||
"library": "server",
|
||||
"windows": "44 88 4C 24 ? 55 56 57 41 54 41 56 48 8D 6C 24 ?",
|
||||
"linux": "55 48 89 E5 41 57 41 56 41 89 D6 41 55 49 89 FD 41 54 45 89 C4"
|
||||
"linux": "55 48 89 E5 41 57 41 56 41 55 49 89 FD 41 54 45 89 C4"
|
||||
}
|
||||
},
|
||||
"CCSPlayerPawnBase_PostThink": {
|
||||
@@ -237,7 +237,7 @@
|
||||
"CEntityResourceManifest_AddResource": {
|
||||
"offsets": {
|
||||
"windows": 2,
|
||||
"linux": 2
|
||||
"linux": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Submodule libraries/hl2sdk-cs2 updated: 739c88fa85...4b31db7505
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* This file is part of CounterStrikeSharp.
|
||||
* CounterStrikeSharp is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* CounterStrikeSharp is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
|
||||
*/
|
||||
|
||||
#include "core/engine_trace.h"
|
||||
|
||||
#include "core/log.h"
|
||||
|
||||
namespace counterstrikesharp {
|
||||
|
||||
CTraceFilterHitAll g_HitAllFilter;
|
||||
|
||||
bool CSimpleTraceFilter::ShouldHitEntity(CEntityInstance *pServerEntity, int contentsMask) {
|
||||
// int index = ExcIndexFromBaseHandle(pServerEntity->GetRefEHandle());
|
||||
// if (index == m_index_to_exclude)
|
||||
// return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TraceType_t TraceFilterProxy::GetTraceType() const {
|
||||
auto nativeContext = fxNativeContext{};
|
||||
auto scriptContext = ScriptContextRaw(nativeContext);
|
||||
|
||||
m_cb_get_trace_type(&nativeContext);
|
||||
|
||||
return scriptContext.GetResult<TraceType_t>();
|
||||
}
|
||||
|
||||
bool TraceFilterProxy::ShouldHitEntity(CEntityInstance *pServerEntity, int contentsMask) {
|
||||
return true;
|
||||
// auto entity = ExcIndexFromBaseHandle(pServerEntity->GetRefEHandle());
|
||||
// if (entity < 0)
|
||||
// return false;
|
||||
//
|
||||
// auto nativeContext = fxNativeContext{};
|
||||
// auto scriptContext = ScriptContextRaw(nativeContext);
|
||||
//
|
||||
// scriptContext.Push(entity);
|
||||
// scriptContext.Push<int>(0);
|
||||
//
|
||||
// m_cb_should_hit_entity(&nativeContext);
|
||||
//
|
||||
// auto result = scriptContext.GetResult<bool>();
|
||||
//
|
||||
// CSSHARP_CORE_INFO("Received result {0} from `ShouldHitEntity`", result);
|
||||
//
|
||||
// return result;
|
||||
/*return result;
|
||||
return true;*/
|
||||
}
|
||||
|
||||
void TraceFilterProxy::SetShouldHitEntityCallback(CallbackT cb) { m_cb_should_hit_entity = cb; }
|
||||
|
||||
void TraceFilterProxy::SetGetTraceTypeCallback(CallbackT cb) { m_cb_get_trace_type = cb; }
|
||||
|
||||
} // namespace counterstrikesharp
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* This file is part of CounterStrikeSharp.
|
||||
* CounterStrikeSharp is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* CounterStrikeSharp is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <public/engine/IEngineTrace.h>
|
||||
|
||||
#include "scripting/callback_manager.h"
|
||||
|
||||
namespace counterstrikesharp {
|
||||
class TraceFilterProxy : public ITraceFilter {
|
||||
public:
|
||||
TraceFilterProxy() {}
|
||||
bool ShouldHitEntity(CEntityInstance *pServerEntity, int contentsMask);
|
||||
TraceType_t GetTraceType() const;
|
||||
|
||||
void SetShouldHitEntityCallback(CallbackT cb);
|
||||
void SetGetTraceTypeCallback(CallbackT cb);
|
||||
|
||||
private:
|
||||
CallbackT m_cb_should_hit_entity;
|
||||
CallbackT m_cb_get_trace_type;
|
||||
};
|
||||
|
||||
class CSimpleTraceFilter : public ITraceFilter {
|
||||
public:
|
||||
CSimpleTraceFilter(int index)
|
||||
: m_index_to_exclude(index) {}
|
||||
bool ShouldHitEntity(CEntityInstance *pServerEntity, int contentsMask);
|
||||
|
||||
TraceType_t GetTraceType() const { return TRACE_EVERYTHING; }
|
||||
|
||||
private:
|
||||
int m_index_to_exclude = -1;
|
||||
};
|
||||
|
||||
enum RayType { RayType_EndPoint, RayType_Infinite };
|
||||
|
||||
} // namespace counterstrikesharp
|
||||
@@ -64,7 +64,7 @@ json WriteTypeJson(json obj, CSchemaType* current_type)
|
||||
|
||||
if (atomicTType->m_pAtomicInfo != nullptr)
|
||||
{
|
||||
obj["outer"] = atomicTType->m_pAtomicInfo->m_pszName1;
|
||||
obj["outer"] = atomicTType->m_pAtomicInfo->m_pszName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ json WriteTypeJson(json obj, CSchemaType* current_type)
|
||||
auto fixedArrayType = static_cast<CSchemaType_FixedArray*>(current_type);
|
||||
obj["inner"] = WriteTypeJson(json::object(), fixedArrayType->m_pElementType);
|
||||
}
|
||||
else if (current_type->m_eTypeCategory == SCHEMA_TYPE_PTR)
|
||||
else if (current_type->m_eTypeCategory == SCHEMA_TYPE_POINTER)
|
||||
{
|
||||
auto ptrType = static_cast<CSchemaType_Ptr*>(current_type);
|
||||
obj["inner"] = WriteTypeJson(json::object(), ptrType->m_pObjectType);
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
// clang-format off
|
||||
#include "mm_plugin.h"
|
||||
#include "core/engine_trace.h"
|
||||
#include "core/timer_system.h"
|
||||
#include "core/utils.h"
|
||||
#include "scripting/autonative.h"
|
||||
@@ -43,16 +42,12 @@ namespace counterstrikesharp {
|
||||
|
||||
const char* GetMapName(ScriptContext& script_context)
|
||||
{
|
||||
if (globals::getGlobalVars() == nullptr)
|
||||
return nullptr;
|
||||
if (globals::getGlobalVars() == nullptr) return nullptr;
|
||||
|
||||
return globals::getGlobalVars()->mapname.ToCStr();
|
||||
}
|
||||
|
||||
const char* GetGameDirectory(ScriptContext& script_context)
|
||||
{
|
||||
return strdup(Plat_GetGameDirectory());
|
||||
}
|
||||
const char* GetGameDirectory(ScriptContext& script_context) { return strdup(Plat_GetGameDirectory()); }
|
||||
|
||||
bool IsMapValid(ScriptContext& script_context)
|
||||
{
|
||||
@@ -60,26 +55,21 @@ bool IsMapValid(ScriptContext& script_context)
|
||||
return globals::engine->IsMapValid(mapname) != 0;
|
||||
}
|
||||
|
||||
float GetTickInterval(ScriptContext& script_context)
|
||||
{
|
||||
return globals::engine_fixed_tick_interval;
|
||||
}
|
||||
float GetTickInterval(ScriptContext& script_context) { return globals::engine_fixed_tick_interval; }
|
||||
|
||||
float GetCurrentTime(ScriptContext& script_context) { return globals::getGlobalVars()->curtime; }
|
||||
|
||||
int GetTickCount(ScriptContext& script_context) { return globals::getGlobalVars()->tickcount; }
|
||||
|
||||
float GetGameFrameTime(ScriptContext& script_context)
|
||||
{
|
||||
return globals::getGlobalVars()->frametime;
|
||||
}
|
||||
float GetGameFrameTime(ScriptContext& script_context) { return globals::getGlobalVars()->frametime; }
|
||||
|
||||
double GetEngineTime(ScriptContext& script_context) { return Plat_FloatTime(); }
|
||||
|
||||
int GetMaxClients(ScriptContext& script_context)
|
||||
{
|
||||
auto globalVars = globals::getGlobalVars();
|
||||
if (globalVars == nullptr) {
|
||||
if (globalVars == nullptr)
|
||||
{
|
||||
script_context.ThrowNativeError("Global Variables not initialized yet.");
|
||||
return -1;
|
||||
}
|
||||
@@ -144,83 +134,6 @@ float GetSoundDuration(ScriptContext& script_context)
|
||||
// attenuation, 0, flags, pitch, origin, direction);
|
||||
// }
|
||||
|
||||
Ray_t* CreateRay1(ScriptContext& script_context)
|
||||
{
|
||||
auto ray_type = script_context.GetArgument<RayType>(0);
|
||||
auto vec1 = script_context.GetArgument<Vector*>(1);
|
||||
auto vec2 = script_context.GetArgument<Vector*>(2);
|
||||
|
||||
Ray_t* pRay = new Ray_t;
|
||||
|
||||
if (ray_type == RayType_EndPoint) {
|
||||
pRay->Init(*vec1, *vec2);
|
||||
return pRay;
|
||||
} else if (ray_type == RayType_Infinite) {
|
||||
QAngle angles;
|
||||
Vector endVec;
|
||||
angles.Init(vec2->x, vec2->y, vec2->z);
|
||||
AngleVectors(angles, &endVec);
|
||||
|
||||
endVec.NormalizeInPlace();
|
||||
endVec = *vec1 + endVec * MAX_TRACE_LENGTH;
|
||||
|
||||
pRay->Init(*vec1, endVec);
|
||||
return pRay;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Ray_t* CreateRay2(ScriptContext& script_context)
|
||||
{
|
||||
auto vec1 = script_context.GetArgument<Vector*>(0);
|
||||
auto vec2 = script_context.GetArgument<Vector*>(1);
|
||||
auto vec3 = script_context.GetArgument<Vector*>(2);
|
||||
auto vec4 = script_context.GetArgument<Vector*>(3);
|
||||
|
||||
Ray_t* pRay = new Ray_t;
|
||||
pRay->Init(*vec1, *vec2, *vec3, *vec4);
|
||||
return pRay;
|
||||
}
|
||||
|
||||
void TraceRay(ScriptContext& script_context)
|
||||
{
|
||||
auto ray = script_context.GetArgument<Ray_t*>(0);
|
||||
auto pTrace = script_context.GetArgument<CGameTrace*>(1);
|
||||
auto trace_filter = script_context.GetArgument<ITraceFilter*>(2);
|
||||
auto flags = script_context.GetArgument<uint32_t>(3);
|
||||
|
||||
globals::engineTrace->TraceRay(*ray, flags, trace_filter, pTrace);
|
||||
}
|
||||
|
||||
CSimpleTraceFilter* NewSimpleTraceFilter(ScriptContext& script_context)
|
||||
{
|
||||
auto index_to_ignore = script_context.GetArgument<int>(0);
|
||||
|
||||
return new CSimpleTraceFilter(index_to_ignore);
|
||||
}
|
||||
|
||||
TraceFilterProxy* NewTraceFilterProxy(ScriptContext& script_context)
|
||||
{
|
||||
return new TraceFilterProxy();
|
||||
}
|
||||
|
||||
void TraceFilterProxySetTraceTypeCallback(ScriptContext& script_context)
|
||||
{
|
||||
auto trace_filter = script_context.GetArgument<TraceFilterProxy*>(0);
|
||||
auto callback = script_context.GetArgument<CallbackT>(1);
|
||||
|
||||
trace_filter->SetGetTraceTypeCallback(callback);
|
||||
}
|
||||
|
||||
void TraceFilterProxySetShouldHitEntityCallback(ScriptContext& script_context)
|
||||
{
|
||||
auto [trace_filter, callback] = script_context.GetArguments<TraceFilterProxy*, CallbackT>();
|
||||
trace_filter->SetShouldHitEntityCallback(callback);
|
||||
}
|
||||
|
||||
CGameTrace* NewTraceResult(ScriptContext& script_context) { return new CGameTrace(); }
|
||||
|
||||
double GetTickedTime(ScriptContext& script_context) { return globals::timerSystem.GetTickedTime(); }
|
||||
|
||||
void QueueTaskForNextFrame(ScriptContext& script_context)
|
||||
@@ -228,7 +141,9 @@ void QueueTaskForNextFrame(ScriptContext& script_context)
|
||||
auto func = script_context.GetArgument<void*>(0);
|
||||
|
||||
typedef void(voidfunc)(void);
|
||||
globals::mmPlugin->AddTaskForNextFrame([func]() { reinterpret_cast<voidfunc*>(func)(); });
|
||||
globals::mmPlugin->AddTaskForNextFrame([func]() {
|
||||
reinterpret_cast<voidfunc*>(func)();
|
||||
});
|
||||
}
|
||||
|
||||
void QueueTaskForNextWorldUpdate(ScriptContext& script_context)
|
||||
@@ -236,7 +151,9 @@ void QueueTaskForNextWorldUpdate(ScriptContext& script_context)
|
||||
auto func = script_context.GetArgument<void*>(0);
|
||||
|
||||
typedef void(voidfunc)(void);
|
||||
globals::serverManager.AddTaskForNextWorldUpdate([func]() { reinterpret_cast<voidfunc*>(func)(); });
|
||||
globals::serverManager.AddTaskForNextWorldUpdate([func]() {
|
||||
reinterpret_cast<voidfunc*>(func)();
|
||||
});
|
||||
}
|
||||
|
||||
void QueueTaskForFrame(ScriptContext& script_context)
|
||||
@@ -259,15 +176,19 @@ void* GetValveInterface(ScriptContext& scriptContext)
|
||||
auto [interfaceType, interfaceName] = scriptContext.GetArguments<InterfaceType, const char*>();
|
||||
|
||||
CreateInterfaceFn factoryFn;
|
||||
if (interfaceType == Server) {
|
||||
if (interfaceType == Server)
|
||||
{
|
||||
factoryFn = globals::ismm->GetServerFactory();
|
||||
} else if (interfaceType == Engine) {
|
||||
}
|
||||
else if (interfaceType == Engine)
|
||||
{
|
||||
factoryFn = globals::ismm->GetEngineFactory();
|
||||
}
|
||||
|
||||
auto foundInterface = globals::ismm->VInterfaceMatch(factoryFn, interfaceName);
|
||||
|
||||
if (foundInterface == nullptr) {
|
||||
if (foundInterface == nullptr)
|
||||
{
|
||||
scriptContext.ThrowNativeError("Could not find interface");
|
||||
}
|
||||
|
||||
@@ -280,33 +201,29 @@ void GetCommandParamValue(ScriptContext& scriptContext)
|
||||
auto paramType = scriptContext.GetArgument<DataType_t>(1);
|
||||
|
||||
int iContextIndex = 2;
|
||||
switch (paramType) {
|
||||
case DATA_TYPE_STRING:
|
||||
scriptContext.SetResult(CommandLine()->ParmValue(
|
||||
paramName, scriptContext.GetArgument<const char*>(iContextIndex)));
|
||||
return;
|
||||
case DATA_TYPE_INT:
|
||||
scriptContext.SetResult(
|
||||
CommandLine()->ParmValue(paramName, scriptContext.GetArgument<int>(iContextIndex)));
|
||||
return;
|
||||
case DATA_TYPE_FLOAT:
|
||||
scriptContext.SetResult(
|
||||
CommandLine()->ParmValue(paramName, scriptContext.GetArgument<float>(iContextIndex)));
|
||||
return;
|
||||
switch (paramType)
|
||||
{
|
||||
case DATA_TYPE_STRING:
|
||||
scriptContext.SetResult(CommandLine()->ParmValue(paramName, scriptContext.GetArgument<const char*>(iContextIndex)));
|
||||
return;
|
||||
case DATA_TYPE_INT:
|
||||
scriptContext.SetResult(CommandLine()->ParmValue(paramName, scriptContext.GetArgument<int>(iContextIndex)));
|
||||
return;
|
||||
case DATA_TYPE_FLOAT:
|
||||
scriptContext.SetResult(CommandLine()->ParmValue(paramName, scriptContext.GetArgument<float>(iContextIndex)));
|
||||
return;
|
||||
}
|
||||
|
||||
scriptContext.ThrowNativeError("Invalid param type");
|
||||
}
|
||||
|
||||
void PrintToServerConsole(ScriptContext& scriptContext) {
|
||||
void PrintToServerConsole(ScriptContext& scriptContext)
|
||||
{
|
||||
auto message = scriptContext.GetArgument<const char*>(0);
|
||||
|
||||
META_CONPRINT(message);
|
||||
}
|
||||
|
||||
CREATE_GETTER_FUNCTION(Trace, bool, DidHit, CGameTrace*, obj->DidHit());
|
||||
CREATE_GETTER_FUNCTION(TraceResult, CBaseEntity*, Entity, CGameTrace*, obj->m_pEnt);
|
||||
|
||||
REGISTER_NATIVES(engine, {
|
||||
ScriptEngine::RegisterNativeHandler("GET_GAME_DIRECTORY", GetGameDirectory);
|
||||
ScriptEngine::RegisterNativeHandler("GET_MAP_NAME", GetMapName);
|
||||
@@ -324,20 +241,6 @@ REGISTER_NATIVES(engine, {
|
||||
ScriptEngine::RegisterNativeHandler("GET_SOUND_DURATION", GetSoundDuration);
|
||||
// ScriptEngine::RegisterNativeHandler("EMIT_SOUND", EmitSound);
|
||||
|
||||
ScriptEngine::RegisterNativeHandler("NEW_SIMPLE_TRACE_FILTER", NewSimpleTraceFilter);
|
||||
ScriptEngine::RegisterNativeHandler("NEW_TRACE_RESULT", NewTraceResult);
|
||||
ScriptEngine::RegisterNativeHandler("TRACE_DID_HIT", TraceGetDidHit);
|
||||
ScriptEngine::RegisterNativeHandler("TRACE_RESULT_ENTITY", TraceResultGetEntity);
|
||||
|
||||
ScriptEngine::RegisterNativeHandler("NEW_TRACE_FILTER_PROXY", NewTraceFilterProxy);
|
||||
ScriptEngine::RegisterNativeHandler("TRACE_FILTER_PROXY_SET_TRACE_TYPE_CALLBACK",
|
||||
TraceFilterProxySetTraceTypeCallback);
|
||||
ScriptEngine::RegisterNativeHandler("TRACE_FILTER_PROXY_SET_SHOULD_HIT_ENTITY_CALLBACK",
|
||||
TraceFilterProxySetShouldHitEntityCallback);
|
||||
|
||||
ScriptEngine::RegisterNativeHandler("CREATE_RAY_1", CreateRay1);
|
||||
ScriptEngine::RegisterNativeHandler("CREATE_RAY_2", CreateRay2);
|
||||
ScriptEngine::RegisterNativeHandler("TRACE_RAY", TraceRay);
|
||||
ScriptEngine::RegisterNativeHandler("GET_TICKED_TIME", GetTickedTime);
|
||||
ScriptEngine::RegisterNativeHandler("QUEUE_TASK_FOR_NEXT_FRAME", QueueTaskForNextFrame);
|
||||
ScriptEngine::RegisterNativeHandler("QUEUE_TASK_FOR_NEXT_WORLD_UPDATE", QueueTaskForNextWorldUpdate);
|
||||
|
||||
Reference in New Issue
Block a user