Re-introduce Address as int64 and remove the opt-in (#2414)
This commit is contained in:
@@ -12,6 +12,3 @@
|
||||
[submodule "public/safetyhook"]
|
||||
path = public/safetyhook
|
||||
url = https://github.com/alliedmodders/safetyhook
|
||||
[submodule "core/logic/libaddrz"]
|
||||
path = core/logic/libaddrz
|
||||
url = https://github.com/dvander/libaddrz.git
|
||||
|
||||
@@ -71,8 +71,6 @@ struct sm_logic_t
|
||||
void (*RegisterProfiler)(IProfilingTool *tool);
|
||||
ICellArray * (*CreateCellArray)(size_t blocksize);
|
||||
void (*FreeCellArray)(ICellArray *arr);
|
||||
void * (*FromPseudoAddress)(uint32_t pseudoAddr);
|
||||
uint32_t (*ToPseudoAddress)(void *addr);
|
||||
void (*SetEntityLumpWritable)(bool writable);
|
||||
bool (*ParseEntityLumpString)(const char *entityString, int &status, size_t &position);
|
||||
const char * (*GetEntityLumpString)();
|
||||
|
||||
+1
-10
@@ -85,16 +85,7 @@ for cxx in builder.targets:
|
||||
'FrameIterator.cpp',
|
||||
'DatabaseConfBuilder.cpp',
|
||||
'LumpManager.cpp',
|
||||
'smn_entitylump.cpp',
|
||||
'libaddrz/addrz.cpp',
|
||||
'libaddrz/mapping.cpp',
|
||||
'libaddrz/platform.cpp',
|
||||
'libaddrz/proc_maps.cpp',
|
||||
'PseudoAddrManager.cpp',
|
||||
'smn_entitylump.cpp'
|
||||
]
|
||||
if binary.compiler.target.platform == 'linux':
|
||||
binary.sources += ['libaddrz/platform_linux.cpp']
|
||||
elif binary.compiler.target.platform == 'windows':
|
||||
binary.sources += ['libaddrz/platform_windows.cpp']
|
||||
|
||||
SM.binaries += [builder.Add(binary)]
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* =============================================================================
|
||||
* SourceMod
|
||||
* Copyright (C) 2004-2017 AlliedModders LLC. All rights reserved.
|
||||
* =============================================================================
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 3.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program 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
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* As a special exception, AlliedModders LLC gives you permission to link the
|
||||
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
||||
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
||||
* by the Valve Corporation. You must obey the GNU General Public License in
|
||||
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
||||
* this exception to all derivative works. AlliedModders LLC defines further
|
||||
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
||||
* or <http://www.sourcemod.net/license.php>.
|
||||
*/
|
||||
|
||||
#include "PseudoAddrManager.h"
|
||||
#include <bridge/include/CoreProvider.h>
|
||||
#ifdef PLATFORM_APPLE
|
||||
#include <mach/mach.h>
|
||||
#include <mach/vm_region.h>
|
||||
#endif
|
||||
#ifdef PLATFORM_LINUX
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
#include <Psapi.h>
|
||||
#endif
|
||||
|
||||
PseudoAddressManager::PseudoAddressManager() : m_dictionary(am::IPlatform::GetDefault())
|
||||
{
|
||||
}
|
||||
|
||||
void PseudoAddressManager::Initialize() {
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
auto process = GetCurrentProcess();
|
||||
auto get_module_details = [process](const char* name, void*& baseAddress, size_t& moduleSize) {
|
||||
if (process == NULL) {
|
||||
return false;
|
||||
}
|
||||
auto hndl = GetModuleHandle(name);
|
||||
if (hndl == NULL) {
|
||||
return false;
|
||||
}
|
||||
MODULEINFO info;
|
||||
if (!GetModuleInformation(process, hndl, &info, sizeof(info))) {
|
||||
return false;
|
||||
}
|
||||
moduleSize = info.SizeOfImage;
|
||||
baseAddress = info.lpBaseOfDll;
|
||||
return true;
|
||||
};
|
||||
#endif
|
||||
#ifdef PLATFORM_LINUX
|
||||
auto get_module_details = [](const char* name, void* baseAddress, size_t& moduleSize) {
|
||||
auto hndl = dlopen(name, RTLD_NOLOAD);
|
||||
if (hndl == NULL) {
|
||||
return false;
|
||||
}
|
||||
void* addr = dlsym(hndl, "CreateInterface");
|
||||
dlclose(hndl);
|
||||
|
||||
if (!addr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Dl_info info;
|
||||
if (dladdr(addr, &info) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
baseAddress = info.dli_fbase;
|
||||
// It doesn't matter much if we figure out the module size
|
||||
// libaddrz coalesce maps on linux
|
||||
moduleSize = 0;
|
||||
return true;
|
||||
};
|
||||
#endif
|
||||
|
||||
// Early map commonly used modules, it's okay if not all of them are here
|
||||
// Everything else will be caught by "ToPseudoAddress" but you risk running out of ranges by then
|
||||
const char* libs[] = { "engine", "server", "tier0", "vstdlib" };
|
||||
|
||||
char formattedName[64];
|
||||
for (int i = 0; i < sizeof(libs) / sizeof(const char*); i++) {
|
||||
bridge->FormatSourceBinaryName(libs[i], formattedName, sizeof(formattedName));
|
||||
void* base_addr = nullptr;
|
||||
size_t module_size = 0;
|
||||
if (get_module_details(formattedName, base_addr, module_size)) {
|
||||
// Create the mapping (hopefully)
|
||||
m_dictionary.Make32bitAddress(base_addr, module_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void *PseudoAddressManager::FromPseudoAddress(uint32_t paddr)
|
||||
{
|
||||
if (paddr == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return m_dictionary.RecoverAddress(paddr).value_or(nullptr);
|
||||
}
|
||||
|
||||
uint32_t PseudoAddressManager::ToPseudoAddress(void *addr)
|
||||
{
|
||||
if (addr == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
return m_dictionary.Make32bitAddress(addr).value_or(0);
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* =============================================================================
|
||||
* SourceMod
|
||||
* Copyright (C) 2004-2017 AlliedModders LLC. All rights reserved.
|
||||
* =============================================================================
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 3.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program 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
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* As a special exception, AlliedModders LLC gives you permission to link the
|
||||
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
||||
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
||||
* by the Valve Corporation. You must obey the GNU General Public License in
|
||||
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
||||
* this exception to all derivative works. AlliedModders LLC defines further
|
||||
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
||||
* or <http://www.sourcemod.net/license.php>.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE_SOURCEMOD_PSEUDOADDRESSMANAGER_H_
|
||||
#define _INCLUDE_SOURCEMOD_PSEUDOADDRESSMANAGER_H_
|
||||
|
||||
#include "common_logic.h"
|
||||
#include "libaddrz/addrz.h"
|
||||
|
||||
class PseudoAddressManager
|
||||
{
|
||||
public:
|
||||
PseudoAddressManager();
|
||||
public:
|
||||
void *FromPseudoAddress(uint32_t paddr);
|
||||
uint32_t ToPseudoAddress(void *addr);
|
||||
void Initialize();
|
||||
private:
|
||||
am::AddressDict m_dictionary;
|
||||
};
|
||||
|
||||
#endif // _INCLUDE_SOURCEMOD_PSEUDOADDRESSMANAGER_H_
|
||||
@@ -57,7 +57,6 @@
|
||||
#include "RootConsoleMenu.h"
|
||||
#include "CellArray.h"
|
||||
#include "smn_entitylump.h"
|
||||
#include "PseudoAddrManager.h"
|
||||
#include <bridge/include/BridgeAPI.h>
|
||||
#include <bridge/include/IProviderCallbacks.h>
|
||||
|
||||
@@ -87,7 +86,6 @@ IScriptManager *scripts = &g_PluginSys;
|
||||
IExtensionSys *extsys = &g_Extensions;
|
||||
ILogger *logger = &g_Logger;
|
||||
CNativeOwner g_CoreNatives;
|
||||
PseudoAddressManager pseudoAddr;
|
||||
|
||||
EntityLumpParseResult lastParseResult;
|
||||
|
||||
@@ -119,16 +117,6 @@ static void RegisterProfiler(IProfilingTool *tool)
|
||||
g_ProfileToolManager.RegisterTool(tool);
|
||||
}
|
||||
|
||||
static void *FromPseudoAddress(uint32_t paddr)
|
||||
{
|
||||
return pseudoAddr.FromPseudoAddress(paddr);
|
||||
}
|
||||
|
||||
static uint32_t ToPseudoAddress(void *addr)
|
||||
{
|
||||
return pseudoAddr.ToPseudoAddress(addr);
|
||||
}
|
||||
|
||||
static void SetEntityLumpWritable(bool writable)
|
||||
{
|
||||
g_bLumpAvailableForWriting = writable;
|
||||
@@ -191,8 +179,6 @@ static sm_logic_t logic =
|
||||
RegisterProfiler,
|
||||
CellArray::New,
|
||||
CellArray::Free,
|
||||
FromPseudoAddress,
|
||||
ToPseudoAddress,
|
||||
SetEntityLumpWritable,
|
||||
ParseEntityLumpString,
|
||||
GetEntityLumpString,
|
||||
@@ -227,7 +213,6 @@ static void logic_init(CoreProvider* core, sm_logic_t* _logic)
|
||||
g_pSourcePawn2 = *core->spe2;
|
||||
SMGlobalClass::head = core->listeners;
|
||||
|
||||
pseudoAddr.Initialize();
|
||||
g_ShareSys.Initialize();
|
||||
g_pCoreIdent = g_ShareSys.CreateCoreIdentity();
|
||||
|
||||
|
||||
@@ -33,9 +33,6 @@
|
||||
#define _INCLUDE_SOURCEMOD_COMMON_LOGIC_H_
|
||||
|
||||
#include "../sm_globals.h"
|
||||
#ifdef KE_ARCH_X64
|
||||
#include "PseudoAddrManager.h"
|
||||
#endif
|
||||
|
||||
namespace SourceMod {
|
||||
class CoreProvider;
|
||||
@@ -60,7 +57,6 @@ class IVEngineServerBridge;
|
||||
#endif
|
||||
} // namespace SourceMod
|
||||
struct ServerGlobals;
|
||||
class PseudoAddressManager;
|
||||
|
||||
extern SourceMod::CoreProvider *bridge;
|
||||
extern SourceMod::IHandleSys *handlesys;
|
||||
@@ -80,7 +76,6 @@ extern SourceMod::IScriptManager *scripts;
|
||||
extern SourceMod::IExtensionSys *extsys;
|
||||
extern SourceMod::ILogger *logger;
|
||||
extern SourceMod::IMenuManager *menus;
|
||||
extern PseudoAddressManager pseudoAddr;
|
||||
|
||||
#if defined SM_LOGIC
|
||||
extern SourceMod::IVEngineServerBridge *engine;
|
||||
|
||||
Submodule core/logic/libaddrz deleted from 003d1cd0a3
+48
-15
@@ -59,7 +59,6 @@
|
||||
#include <bridge/include/CoreProvider.h>
|
||||
#include <bridge/include/IScriptManager.h>
|
||||
#include <bridge/include/IExtensionBridge.h>
|
||||
#include "PseudoAddrManager.h"
|
||||
#include <sh_vector.h>
|
||||
|
||||
using namespace SourceMod;
|
||||
@@ -865,8 +864,13 @@ enum NumberType
|
||||
static cell_t LoadFromAddress(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
void *addr = reinterpret_cast<void*>(params[1]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
addr = pseudoAddr.FromPseudoAddress(params[1]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
cell_t* sp_addr;
|
||||
if (int err = pContext->LocalToPhysAddr(params[1], &sp_addr); err != SP_ERROR_NONE) {
|
||||
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
|
||||
}
|
||||
auto value = *reinterpret_cast<int64_t*>(sp_addr);
|
||||
addr = (void*)value;
|
||||
}
|
||||
|
||||
if (addr == NULL)
|
||||
@@ -895,8 +899,13 @@ static cell_t LoadFromAddress(IPluginContext *pContext, const cell_t *params)
|
||||
static cell_t StoreToAddress(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
void *addr = reinterpret_cast<void*>(params[1]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
addr = pseudoAddr.FromPseudoAddress(params[1]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
cell_t* sp_addr;
|
||||
if (int err = pContext->LocalToPhysAddr(params[1], &sp_addr); err != SP_ERROR_NONE) {
|
||||
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
|
||||
}
|
||||
auto value = *reinterpret_cast<int64_t*>(sp_addr);
|
||||
addr = (void*)value;
|
||||
}
|
||||
|
||||
if (addr == NULL)
|
||||
@@ -950,9 +959,19 @@ static cell_t StoreToAddress(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
static cell_t LoadAddressFromAddress(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
void *addr = reinterpret_cast<void*>(params[1]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
addr = pseudoAddr.FromPseudoAddress(params[1]);
|
||||
cell_t shift_param = 0;
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
shift_param = 1;
|
||||
}
|
||||
|
||||
void *addr = reinterpret_cast<void*>(params[shift_param + 1]);
|
||||
if (shift_param != 0) {
|
||||
cell_t* sp_addr;
|
||||
if (int err = pContext->LocalToPhysAddr(params[shift_param + 1], &sp_addr); err != SP_ERROR_NONE) {
|
||||
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
|
||||
}
|
||||
auto value = *reinterpret_cast<int64_t*>(sp_addr);
|
||||
addr = (void*)value;
|
||||
}
|
||||
|
||||
if (addr == NULL)
|
||||
@@ -963,10 +982,14 @@ static cell_t LoadAddressFromAddress(IPluginContext *pContext, const cell_t *par
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid address 0x%x is pointing to reserved memory.", addr);
|
||||
}
|
||||
|
||||
void* data = *reinterpret_cast<void**>(addr);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
return pseudoAddr.ToPseudoAddress(data);
|
||||
|
||||
if (shift_param != 0) {
|
||||
cell_t* sp_addr;
|
||||
if (int err = pContext->LocalToPhysAddr(params[1], &sp_addr); err != SP_ERROR_NONE) {
|
||||
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
|
||||
}
|
||||
*reinterpret_cast<int64_t*>(sp_addr) = reinterpret_cast<uintptr_t>(data);
|
||||
}
|
||||
return reinterpret_cast<uintptr_t>(data);
|
||||
}
|
||||
@@ -974,8 +997,13 @@ static cell_t LoadAddressFromAddress(IPluginContext *pContext, const cell_t *par
|
||||
static cell_t StoreAddressToAddress(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
void *addr = reinterpret_cast<void*>(params[1]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
addr = pseudoAddr.FromPseudoAddress(params[1]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
cell_t* sp_addr;
|
||||
if (int err = pContext->LocalToPhysAddr(params[1], &sp_addr); err != SP_ERROR_NONE) {
|
||||
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
|
||||
}
|
||||
auto value = *reinterpret_cast<int64_t*>(sp_addr);
|
||||
addr = (void*)value;
|
||||
}
|
||||
|
||||
if (addr == NULL)
|
||||
@@ -988,8 +1016,13 @@ static cell_t StoreAddressToAddress(IPluginContext *pContext, const cell_t *para
|
||||
}
|
||||
|
||||
void *data = reinterpret_cast<void*>(params[2]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
data = pseudoAddr.FromPseudoAddress(params[2]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
cell_t* sp_addr;
|
||||
if (int err = pContext->LocalToPhysAddr(params[2], &sp_addr); err != SP_ERROR_NONE) {
|
||||
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
|
||||
}
|
||||
auto value = *reinterpret_cast<int64_t*>(sp_addr);
|
||||
data = (void*)value;
|
||||
}
|
||||
|
||||
bool updateMemAccess = params[3];
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include "common_logic.h"
|
||||
#include <IHandleSys.h>
|
||||
#include "GameConfigs.h"
|
||||
#include "PseudoAddrManager.h"
|
||||
|
||||
HandleType_t g_GameConfigsType;
|
||||
|
||||
@@ -135,7 +134,12 @@ static cell_t smn_GameConfGetKeyValue(IPluginContext *pCtx, const cell_t *params
|
||||
|
||||
static cell_t smn_GameConfGetAddress(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
cell_t shift_param = 0;
|
||||
if (pCtx->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
shift_param = 1;
|
||||
}
|
||||
|
||||
Handle_t hndl = static_cast<Handle_t>(params[shift_param + 1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
IGameConfig *gc;
|
||||
@@ -151,20 +155,30 @@ static cell_t smn_GameConfGetAddress(IPluginContext *pCtx, const cell_t *params)
|
||||
|
||||
char *key;
|
||||
void* val;
|
||||
pCtx->LocalToString(params[2], &key);
|
||||
pCtx->LocalToString(params[shift_param + 2], &key);
|
||||
|
||||
if (!gc->GetAddress(key, &val))
|
||||
return 0;
|
||||
if (!gc->GetAddress(key, &val)) {
|
||||
val = nullptr;
|
||||
}
|
||||
|
||||
if (pCtx->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
return pseudoAddr.ToPseudoAddress(val);
|
||||
if (shift_param != 0) {
|
||||
cell_t* sp_addr;
|
||||
if (int err = pCtx->LocalToPhysAddr(params[1], &sp_addr); err != SP_ERROR_NONE) {
|
||||
return pCtx->ThrowNativeErrorEx(err, "Could not read argument");
|
||||
}
|
||||
*reinterpret_cast<int64_t*>(sp_addr) = reinterpret_cast<uintptr_t>(val);
|
||||
}
|
||||
return reinterpret_cast<uintptr_t>(val);
|
||||
}
|
||||
|
||||
static cell_t smn_GameConfGetMemSig(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
cell_t shift_param = 0;
|
||||
if (pCtx->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
shift_param = 1;
|
||||
}
|
||||
|
||||
Handle_t hndl = static_cast<Handle_t>(params[shift_param + 1]);
|
||||
HandleError herr;
|
||||
HandleSecurity sec;
|
||||
IGameConfig *gc;
|
||||
@@ -180,15 +194,19 @@ static cell_t smn_GameConfGetMemSig(IPluginContext *pCtx, const cell_t *params)
|
||||
|
||||
char *key;
|
||||
void *val;
|
||||
pCtx->LocalToString(params[2], &key);
|
||||
pCtx->LocalToString(params[shift_param + 2], &key);
|
||||
|
||||
if (!gc->GetMemSig(key, &val))
|
||||
{
|
||||
return 0;
|
||||
val = nullptr;
|
||||
}
|
||||
|
||||
if (pCtx->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
return pseudoAddr.ToPseudoAddress(val);
|
||||
if (shift_param != 0) {
|
||||
cell_t* sp_addr;
|
||||
if (int err = pCtx->LocalToPhysAddr(params[1], &sp_addr); err != SP_ERROR_NONE) {
|
||||
return pCtx->ThrowNativeErrorEx(err, "Could not read argument");
|
||||
}
|
||||
*reinterpret_cast<int64_t*>(sp_addr) = reinterpret_cast<uintptr_t>(val);
|
||||
}
|
||||
return reinterpret_cast<uintptr_t>(val);
|
||||
}
|
||||
|
||||
+26
-7
@@ -725,8 +725,13 @@ static cell_t GetEntDataEnt2(IPluginContext *pContext, const cell_t *params)
|
||||
static cell_t LoadEntityFromHandleAddress(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
void *addr = reinterpret_cast<void*>(params[1]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
addr = g_SourceMod.FromPseudoAddress(params[1]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
cell_t* sp_addr;
|
||||
if (int err = pContext->LocalToPhysAddr(params[1], &sp_addr); err != SP_ERROR_NONE) {
|
||||
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
|
||||
}
|
||||
auto value = *reinterpret_cast<int64_t*>(sp_addr);
|
||||
addr = (void*)value;
|
||||
}
|
||||
|
||||
if (addr == NULL)
|
||||
@@ -835,8 +840,13 @@ static cell_t SetEntDataEnt2(IPluginContext *pContext, const cell_t *params)
|
||||
static cell_t StoreEntityToHandleAddress(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
void *addr = reinterpret_cast<void*>(params[1]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
addr = g_SourceMod.FromPseudoAddress(params[1]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
cell_t* sp_addr;
|
||||
if (int err = pContext->LocalToPhysAddr(params[1], &sp_addr); err != SP_ERROR_NONE) {
|
||||
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
|
||||
}
|
||||
auto value = *reinterpret_cast<int64_t*>(sp_addr);
|
||||
addr = (void*)value;
|
||||
}
|
||||
|
||||
if (addr == NULL)
|
||||
@@ -2764,14 +2774,23 @@ static cell_t SetEntityFlags(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
static cell_t GetEntityAddress(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
CBaseEntity * pEntity = GetEntity(params[1]);
|
||||
cell_t shift_param = 0;
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
shift_param = 1;
|
||||
}
|
||||
|
||||
CBaseEntity * pEntity = GetEntity(params[shift_param + 1]);
|
||||
if (!pEntity)
|
||||
{
|
||||
return pContext->ThrowNativeError("Entity %d (%d) is invalid", g_HL2.ReferenceToIndex(params[1]), params[1]);
|
||||
}
|
||||
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
return g_SourceMod.ToPseudoAddress(pEntity);
|
||||
if (shift_param != 0) {
|
||||
cell_t* sp_addr;
|
||||
if (int err = pContext->LocalToPhysAddr(params[1], &sp_addr); err != SP_ERROR_NONE) {
|
||||
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
|
||||
}
|
||||
*reinterpret_cast<int64_t*>(sp_addr) = reinterpret_cast<uintptr_t>(pEntity);
|
||||
}
|
||||
return reinterpret_cast<uintptr_t>(pEntity);
|
||||
}
|
||||
|
||||
@@ -832,16 +832,6 @@ bool SourceModBase::IsMapRunning()
|
||||
return g_OnMapStarted;
|
||||
}
|
||||
|
||||
void *SourceModBase::FromPseudoAddress(uint32_t pseudoAddr)
|
||||
{
|
||||
return logicore.FromPseudoAddress(pseudoAddr);
|
||||
}
|
||||
|
||||
uint32_t SourceModBase::ToPseudoAddress(void *addr)
|
||||
{
|
||||
return logicore.ToPseudoAddress(addr);
|
||||
}
|
||||
|
||||
class ConVarRegistrar :
|
||||
public IConCommandBaseAccessor,
|
||||
public SMGlobalClass
|
||||
|
||||
@@ -135,8 +135,6 @@ public: // ISourceMod
|
||||
int GetPluginId();
|
||||
int GetShApiVersion();
|
||||
bool IsMapRunning();
|
||||
void *FromPseudoAddress(uint32_t pseudoAddr);
|
||||
uint32_t ToPseudoAddress(void *addr);
|
||||
private:
|
||||
void ShutdownServices();
|
||||
private:
|
||||
|
||||
@@ -50,7 +50,7 @@ for cxx in builder.targets:
|
||||
SM.AddCDetour(binary)
|
||||
|
||||
if binary.compiler.target.arch == 'x86':
|
||||
binary.sources += ['../../sourcepawn/vm/x86/assembler-x86.cpp']
|
||||
#binary.sources += ['../../sourcepawn/vm/x86/assembler-x86.cpp']
|
||||
|
||||
binary.compiler.cxxincludes += [
|
||||
os.path.join(builder.sourcePath, 'public', 'jit', 'x86'),
|
||||
|
||||
@@ -109,7 +109,7 @@ bool AddDetourPluginHook(HookType_t hookType, CHook *pDetour, HookSetup *setup,
|
||||
}
|
||||
|
||||
// Add the plugin callback to the detour list.
|
||||
CDynamicHooksSourcePawn *pWrapper = new CDynamicHooksSourcePawn(setup, pDetour, pCallback, hookType == HOOKTYPE_POST);
|
||||
CDynamicHooksSourcePawn *pWrapper = new CDynamicHooksSourcePawn(setup, pDetour, pCallback, pCallback->GetParentRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE, hookType == HOOKTYPE_POST);
|
||||
wrappers->push_back(pWrapper);
|
||||
|
||||
return true;
|
||||
@@ -375,9 +375,21 @@ ReturnAction_t HandleDetour(HookType_t hookType, CHook* pDetour)
|
||||
if (pWrapper->callConv == CallConv_THISCALL && pWrapper->thisType != ThisPointer_Ignore)
|
||||
{
|
||||
// The this pointer is implicitly always the first argument.
|
||||
void *thisPtr = pDetour->GetArgument<void *>(0);
|
||||
cell_t thisAddr = GetThisPtr(pCallback->GetParentContext(), thisPtr, pWrapper->thisType);
|
||||
pCallback->PushCell(thisAddr);
|
||||
auto thisAddr = pDetour->GetArgument<void *>(0);
|
||||
if (pWrapper->thisType == ThisPointer_CBaseEntity) {
|
||||
if (thisAddr == nullptr) {
|
||||
pWrapper->plugin_callback->PushCell(-1);
|
||||
} else {
|
||||
pWrapper->plugin_callback->PushCell(gamehelpers->EntityToBCompatRef((CBaseEntity *)thisAddr));
|
||||
}
|
||||
} else {
|
||||
if (pWrapper->int64_address) {
|
||||
std::int64_t addr = reinterpret_cast<std::int64_t>(thisAddr);
|
||||
pWrapper->plugin_callback->PushArray(reinterpret_cast<cell_t*>(&addr), 2);
|
||||
} else {
|
||||
pWrapper->plugin_callback->PushCell((cell_t)thisAddr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create the structure for plugins to change/get the return value if the function returns something.
|
||||
@@ -519,7 +531,7 @@ ReturnAction_t HandleDetour(HookType_t hookType, CHook* pDetour)
|
||||
return finalRet;
|
||||
}
|
||||
|
||||
CDynamicHooksSourcePawn::CDynamicHooksSourcePawn(HookSetup *setup, CHook *pDetour, IPluginFunction *pCallback, bool post)
|
||||
CDynamicHooksSourcePawn::CDynamicHooksSourcePawn(HookSetup *setup, CHook *pDetour, IPluginFunction *pCallback, bool int64_addr, bool post)
|
||||
{
|
||||
this->params = setup->params;
|
||||
this->offset = -1;
|
||||
@@ -532,6 +544,7 @@ CDynamicHooksSourcePawn::CDynamicHooksSourcePawn(HookSetup *setup, CHook *pDetou
|
||||
this->hookType = setup->hookType;
|
||||
this->m_pDetour = pDetour;
|
||||
this->callConv = setup->callConv;
|
||||
this->int64_address = int64_addr;
|
||||
this->thisFuncCallConv = setup->callConv;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ extern DetourMap g_pPostDetours;
|
||||
|
||||
class CDynamicHooksSourcePawn : public DHooksInfo {
|
||||
public:
|
||||
CDynamicHooksSourcePawn(HookSetup *setup, CHook *pDetour, IPluginFunction *pCallback, bool post);
|
||||
CDynamicHooksSourcePawn(HookSetup *setup, CHook *pDetour, IPluginFunction *pCallback, bool int64_address, bool post);
|
||||
|
||||
HookReturnStruct *GetReturnStruct();
|
||||
HookParamsStruct *GetParamStruct();
|
||||
|
||||
@@ -174,9 +174,14 @@ cell_t Native_CreateHook(IPluginContext *pContext, const cell_t *params)
|
||||
//native Handle:DHookCreateDetour(Address:funcaddr, CallingConvention:callConv, ReturnType:returntype, ThisPointerType:thistype);
|
||||
cell_t Native_CreateDetour(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
void* addr = reinterpret_cast<void*>(params[1]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
addr = g_pSM->FromPseudoAddress(params[1]);
|
||||
void *addr = reinterpret_cast<void*>(params[1]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
cell_t* sp_addr;
|
||||
if (int err = pContext->LocalToPhysAddr(params[1], &sp_addr); err != SP_ERROR_NONE) {
|
||||
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
|
||||
}
|
||||
auto value = *reinterpret_cast<int64_t*>(sp_addr);
|
||||
addr = (void*)value;
|
||||
}
|
||||
|
||||
HookSetup *setup = new HookSetup((ReturnType)params[3], PASSFLAG_BYVAL, (CallingConvention)params[2], (ThisPointerType)params[4], addr);
|
||||
@@ -646,9 +651,14 @@ cell_t HookRawImpl(IPluginContext *pContext, const cell_t *params, int callbackI
|
||||
if (removalcbIndex > 0)
|
||||
removalcb = pContext->GetFunctionById(params[removalcbIndex]);
|
||||
|
||||
void* iface = reinterpret_cast<void*>(params[3]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
iface = g_pSM->FromPseudoAddress(params[3]);
|
||||
void *iface = reinterpret_cast<void*>(params[3]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
cell_t* sp_addr;
|
||||
if (int err = pContext->LocalToPhysAddr(params[3], &sp_addr); err != SP_ERROR_NONE) {
|
||||
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
|
||||
}
|
||||
auto value = *reinterpret_cast<int64_t*>(sp_addr);
|
||||
iface = (void*)value;
|
||||
}
|
||||
|
||||
for(int i = g_pHooks.size() -1; i >= 0; i--)
|
||||
@@ -1469,19 +1479,24 @@ cell_t Native_IsNullParam(IPluginContext *pContext, const cell_t *params)
|
||||
//native Address:DHookGetParamAddress(Handle:hParams, num);
|
||||
cell_t Native_GetParamAddress(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
cell_t shift_param = 0;
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
shift_param = 1;
|
||||
}
|
||||
|
||||
HookParamsStruct *paramStruct;
|
||||
|
||||
if(!GetCallbackArgHandleIfValidOrError(g_HookParamsHandle, g_HookReturnHandle, (void **)¶mStruct, pContext, params[1]))
|
||||
if(!GetCallbackArgHandleIfValidOrError(g_HookParamsHandle, g_HookReturnHandle, (void **)¶mStruct, pContext, params[shift_param + 1]))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(params[2] <= 0 || params[2] > (int)paramStruct->dg->params.size())
|
||||
if(params[shift_param + 2] <= 0 || params[shift_param + 2] > (int)paramStruct->dg->params.size())
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size());
|
||||
return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[shift_param + 2], paramStruct->dg->params.size());
|
||||
}
|
||||
|
||||
int index = params[2] - 1;
|
||||
int index = params[shift_param + 2] - 1;
|
||||
|
||||
HookParamType type = paramStruct->dg->params.at(index).type;
|
||||
if(type != HookParamType_StringPtr && type != HookParamType_CharPtr && type != HookParamType_VectorPtr && type != HookParamType_CBaseEntity && type != HookParamType_ObjectPtr && type != HookParamType_Edict && type != HookParamType_Unknown)
|
||||
@@ -1491,10 +1506,16 @@ cell_t Native_GetParamAddress(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
size_t offset = GetParamOffset(paramStruct, index);
|
||||
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
return g_pSM->ToPseudoAddress(*(void**)((intptr_t)paramStruct->orgParams + offset));
|
||||
auto return_ptr = *(void**)((intptr_t)paramStruct->orgParams + offset);
|
||||
|
||||
if (shift_param != 0) {
|
||||
cell_t* sp_addr;
|
||||
if (int err = pContext->LocalToPhysAddr(params[1], &sp_addr); err != SP_ERROR_NONE) {
|
||||
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
|
||||
}
|
||||
*reinterpret_cast<int64_t*>(sp_addr) = reinterpret_cast<uintptr_t>(return_ptr);
|
||||
}
|
||||
return *(cell_t *)((intptr_t)paramStruct->orgParams + offset);
|
||||
return reinterpret_cast<uintptr_t>(return_ptr);
|
||||
}
|
||||
|
||||
sp_nativeinfo_t g_Natives[] =
|
||||
|
||||
+60
-18
@@ -465,20 +465,6 @@ HookReturnStruct *GetReturnStruct(DHooksCallback *dg)
|
||||
return res;
|
||||
}
|
||||
|
||||
cell_t GetThisPtr(IPluginContext* pContext, void *iface, ThisPointerType type)
|
||||
{
|
||||
if (type == ThisPointer_CBaseEntity)
|
||||
{
|
||||
if (!iface)
|
||||
return -1;
|
||||
return gamehelpers->EntityToBCompatRef((CBaseEntity *)iface);
|
||||
}
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
return g_pSM->ToPseudoAddress(iface);
|
||||
}
|
||||
return (cell_t)iface;
|
||||
}
|
||||
|
||||
#if defined( WIN32 ) && !defined( KE_ARCH_X64 )
|
||||
void *Callback(DHooksCallback *dg, void **argStack, size_t *argsizep)
|
||||
#else
|
||||
@@ -499,7 +485,21 @@ void *Callback(DHooksCallback *dg, void **argStack)
|
||||
|
||||
if(dg->thisType == ThisPointer_CBaseEntity || dg->thisType == ThisPointer_Address)
|
||||
{
|
||||
dg->plugin_callback->PushCell(GetThisPtr(dg->plugin_callback->GetParentContext(), g_SHPtr->GetIfacePtr(), dg->thisType));
|
||||
auto thisAddr = g_SHPtr->GetIfacePtr();
|
||||
if (dg->thisType == ThisPointer_CBaseEntity) {
|
||||
if (thisAddr == nullptr) {
|
||||
dg->plugin_callback->PushCell(-1);
|
||||
} else {
|
||||
dg->plugin_callback->PushCell(gamehelpers->EntityToBCompatRef((CBaseEntity *)thisAddr));
|
||||
}
|
||||
} else {
|
||||
if (dg->int64_address) {
|
||||
std::int64_t addr = reinterpret_cast<std::int64_t>(thisAddr);
|
||||
dg->plugin_callback->PushArray(reinterpret_cast<cell_t*>(&addr), 2);
|
||||
} else {
|
||||
dg->plugin_callback->PushCell((cell_t)thisAddr);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(dg->returnType != ReturnType_Void)
|
||||
{
|
||||
@@ -683,7 +683,21 @@ float Callback_float(DHooksCallback *dg, void **argStack)
|
||||
|
||||
if(dg->thisType == ThisPointer_CBaseEntity || dg->thisType == ThisPointer_Address)
|
||||
{
|
||||
dg->plugin_callback->PushCell(GetThisPtr(dg->plugin_callback->GetParentContext(), g_SHPtr->GetIfacePtr(), dg->thisType));
|
||||
auto thisAddr = g_SHPtr->GetIfacePtr();
|
||||
if (dg->thisType == ThisPointer_CBaseEntity) {
|
||||
if (thisAddr == nullptr) {
|
||||
dg->plugin_callback->PushCell(-1);
|
||||
} else {
|
||||
dg->plugin_callback->PushCell(gamehelpers->EntityToBCompatRef((CBaseEntity *)thisAddr));
|
||||
}
|
||||
} else {
|
||||
if (dg->int64_address) {
|
||||
std::int64_t addr = reinterpret_cast<std::int64_t>(thisAddr);
|
||||
dg->plugin_callback->PushArray(reinterpret_cast<cell_t*>(&addr), 2);
|
||||
} else {
|
||||
dg->plugin_callback->PushCell((cell_t)thisAddr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
returnStruct = GetReturnStruct(dg);
|
||||
@@ -840,7 +854,21 @@ SDKVector *Callback_vector(DHooksCallback *dg, void **argStack)
|
||||
|
||||
if(dg->thisType == ThisPointer_CBaseEntity || dg->thisType == ThisPointer_Address)
|
||||
{
|
||||
dg->plugin_callback->PushCell(GetThisPtr(dg->plugin_callback->GetParentContext(), g_SHPtr->GetIfacePtr(), dg->thisType));
|
||||
auto thisAddr = g_SHPtr->GetIfacePtr();
|
||||
if (dg->thisType == ThisPointer_CBaseEntity) {
|
||||
if (thisAddr == nullptr) {
|
||||
dg->plugin_callback->PushCell(-1);
|
||||
} else {
|
||||
dg->plugin_callback->PushCell(gamehelpers->EntityToBCompatRef((CBaseEntity *)thisAddr));
|
||||
}
|
||||
} else {
|
||||
if (dg->int64_address) {
|
||||
std::int64_t addr = reinterpret_cast<std::int64_t>(thisAddr);
|
||||
dg->plugin_callback->PushArray(reinterpret_cast<cell_t*>(&addr), 2);
|
||||
} else {
|
||||
dg->plugin_callback->PushCell((cell_t)thisAddr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
returnStruct = GetReturnStruct(dg);
|
||||
@@ -994,7 +1022,21 @@ string_t *Callback_stringt(DHooksCallback *dg, void **argStack)
|
||||
|
||||
if(dg->thisType == ThisPointer_CBaseEntity || dg->thisType == ThisPointer_Address)
|
||||
{
|
||||
dg->plugin_callback->PushCell(GetThisPtr(dg->plugin_callback->GetParentContext(), g_SHPtr->GetIfacePtr(), dg->thisType));
|
||||
auto thisAddr = g_SHPtr->GetIfacePtr();
|
||||
if (dg->thisType == ThisPointer_CBaseEntity) {
|
||||
if (thisAddr == nullptr) {
|
||||
dg->plugin_callback->PushCell(-1);
|
||||
} else {
|
||||
dg->plugin_callback->PushCell(gamehelpers->EntityToBCompatRef((CBaseEntity *)thisAddr));
|
||||
}
|
||||
} else {
|
||||
if (dg->int64_address) {
|
||||
std::int64_t addr = reinterpret_cast<std::int64_t>(thisAddr);
|
||||
dg->plugin_callback->PushArray(reinterpret_cast<cell_t*>(&addr), 2);
|
||||
} else {
|
||||
dg->plugin_callback->PushCell((cell_t)thisAddr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
returnStruct = GetReturnStruct(dg);
|
||||
|
||||
@@ -159,6 +159,7 @@ public:
|
||||
ReturnType returnType;
|
||||
bool post;
|
||||
IPluginFunction *plugin_callback;
|
||||
bool int64_address;
|
||||
int entity;
|
||||
ThisPointerType thisType;
|
||||
HookType hookType;
|
||||
@@ -339,7 +340,6 @@ public:
|
||||
};
|
||||
|
||||
size_t GetStackArgsSize(DHooksCallback *dg);
|
||||
cell_t GetThisPtr(IPluginContext* pContext, void *iface, ThisPointerType type);
|
||||
|
||||
extern IBinTools *g_pBinTools;
|
||||
extern HandleType_t g_HookParamsHandle;
|
||||
|
||||
@@ -64,7 +64,7 @@ inline void DecodePassMethod(ValveType vtype, SDKPassMethod method, PassType &ty
|
||||
if (vtype == Valve_POD
|
||||
|| vtype == Valve_Float
|
||||
|| vtype == Valve_Bool
|
||||
|| vtype == Valve_VirtualAddress)
|
||||
|| vtype == Valve_SMAddress)
|
||||
{
|
||||
flags = PASSFLAG_BYVAL | PASSFLAG_ASPOINTER;
|
||||
} else {
|
||||
@@ -88,12 +88,6 @@ inline void DecodePassMethod(ValveType vtype, SDKPassMethod method, PassType &ty
|
||||
static cell_t StartPrepSDKCall(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
auto call_type = (ValveCallType)params[1];
|
||||
if (call_type == ValveCall_Raw && pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
return pContext->ThrowNativeError("SDKCall_Raw is unavailable for plugins that have enabled virtual address.");
|
||||
}
|
||||
if (call_type == ValveCall_VirtualAddress && pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) != SP_ERROR_NONE) {
|
||||
return pContext->ThrowNativeError("SDKCall_VirtualAddress is unavailable for plugins that haven't enabled virtual address.");
|
||||
}
|
||||
s_numparams = 0;
|
||||
s_vtbl_index = -1;
|
||||
s_call_addr = NULL;
|
||||
@@ -181,8 +175,13 @@ static cell_t PrepSDKCall_SetSignature(IPluginContext *pContext, const cell_t *p
|
||||
static cell_t PrepSDKCall_SetAddress(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
s_call_addr = reinterpret_cast<void*>(params[1]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
s_call_addr = g_pSM->FromPseudoAddress(params[1]);
|
||||
if (pContext->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
|
||||
cell_t* sp_addr;
|
||||
if (int err = pContext->LocalToPhysAddr(params[1], &sp_addr); err != SP_ERROR_NONE) {
|
||||
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
|
||||
}
|
||||
auto value = *reinterpret_cast<int64_t*>(sp_addr);
|
||||
s_call_addr = (void*)value;
|
||||
}
|
||||
|
||||
return (s_call_addr != NULL) ? 1 : 0;
|
||||
@@ -403,37 +402,7 @@ static cell_t SDKCall(IPluginContext *pContext, const cell_t *params)
|
||||
//note: varargs pawn args are passed by-ref
|
||||
cell_t *cell;
|
||||
pContext->LocalToPhysAddr(params[startparam], &cell);
|
||||
void *thisptr = reinterpret_cast<void*>(*cell);
|
||||
|
||||
if (thisptr == nullptr)
|
||||
{
|
||||
vc->stk_put(ptr);
|
||||
return pContext->ThrowNativeError("ThisPtr address cannot be null");
|
||||
}
|
||||
else if (reinterpret_cast<uintptr_t>(thisptr) < VALID_MINIMUM_MEMORY_ADDRESS)
|
||||
{
|
||||
vc->stk_put(ptr);
|
||||
return pContext->ThrowNativeError("Invalid ThisPtr address %p is pointing to reserved memory.", thisptr);
|
||||
}
|
||||
|
||||
*(void **)ptr = thisptr;
|
||||
startparam++;
|
||||
}
|
||||
break;
|
||||
case ValveCall_VirtualAddress:
|
||||
{
|
||||
//params[startparam] is an address to a pointer to THIS
|
||||
//params following this are params to the method we will invoke later
|
||||
if (startparam > numparams)
|
||||
{
|
||||
vc->stk_put(ptr);
|
||||
return pContext->ThrowNativeError("Expected a ThisPtr address, it wasn't found");
|
||||
}
|
||||
|
||||
//note: varargs pawn args are passed by-ref
|
||||
cell_t *cell;
|
||||
pContext->LocalToPhysAddr(params[startparam], &cell);
|
||||
void* thisptr = reinterpret_cast<void*>(g_pSM->FromPseudoAddress(*cell));
|
||||
void *thisptr = *reinterpret_cast<void**>(cell);
|
||||
|
||||
if (thisptr == nullptr)
|
||||
{
|
||||
@@ -467,6 +436,9 @@ static cell_t SDKCall(IPluginContext *pContext, const cell_t *params)
|
||||
startparam += 2;
|
||||
} else if (vc->retinfo->vtype == Valve_Vector
|
||||
|| vc->retinfo->vtype == Valve_QAngle)
|
||||
{
|
||||
startparam += 1;
|
||||
} else if (vc->retinfo->vtype == Valve_SMAddress)
|
||||
{
|
||||
startparam += 1;
|
||||
}
|
||||
@@ -573,13 +545,22 @@ static cell_t SDKCall(IPluginContext *pContext, const cell_t *params)
|
||||
addr = *(bool **)addr;
|
||||
}
|
||||
return *addr ? 1 : 0;
|
||||
} else if (vc->retinfo->vtype == Valve_VirtualAddress) {
|
||||
void *addr = *(void **)vc->retbuf;
|
||||
} else if (vc->retinfo->vtype == Valve_SMAddress) {
|
||||
if (numparams < 3)
|
||||
{
|
||||
return pContext->ThrowNativeError("Expected argument (3) for VirtualAddress storage");
|
||||
}
|
||||
void *addr = *(void **)vc->retbuf;
|
||||
if (vc->retinfo->flags & PASSFLAG_ASPOINTER)
|
||||
{
|
||||
addr = *(void **)addr;
|
||||
}
|
||||
return g_pSM->ToPseudoAddress(addr);
|
||||
cell_t* sp_addr;
|
||||
if (int err = pContext->LocalToPhysAddr(params[retparam], &sp_addr); err != SP_ERROR_NONE) {
|
||||
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
|
||||
}
|
||||
*reinterpret_cast<int64_t*>(sp_addr) = reinterpret_cast<intptr_t>(addr);
|
||||
return 0;
|
||||
} else {
|
||||
cell_t *addr = (cell_t *)vc->retbuf;
|
||||
if (vc->retinfo->flags & PASSFLAG_ASPOINTER)
|
||||
|
||||
@@ -164,7 +164,7 @@ size_t ValveParamToBinParam(ValveType type,
|
||||
return sizeof(float);
|
||||
}
|
||||
}
|
||||
case Valve_VirtualAddress:
|
||||
case Valve_SMAddress:
|
||||
{
|
||||
info->flags = flags;
|
||||
if (flags & PASSFLAG_ASPOINTER)
|
||||
@@ -293,16 +293,18 @@ DataStatus EncodeValveParam(IPluginContext *pContext,
|
||||
|
||||
return Data_Okay;
|
||||
}
|
||||
case Valve_VirtualAddress:
|
||||
case Valve_SMAddress:
|
||||
{
|
||||
cell_t *addr;
|
||||
pContext->LocalToPhysAddr(param, &addr);
|
||||
|
||||
if (data->flags & PASSFLAG_ASPOINTER)
|
||||
{
|
||||
buffer = *(void **)buffer;
|
||||
}
|
||||
*addr = g_pSM->ToPseudoAddress(*(void**)buffer);
|
||||
|
||||
cell_t* sp_addr;
|
||||
if (pContext->LocalToPhysAddr(param, &sp_addr) != SP_ERROR_NONE) {
|
||||
return Data_Fail;
|
||||
}
|
||||
*reinterpret_cast<int64_t*>(sp_addr) = reinterpret_cast<intptr_t>(*(void**)buffer);
|
||||
|
||||
return Data_Okay;
|
||||
}
|
||||
@@ -613,7 +615,7 @@ DataStatus DecodeValveParam(IPluginContext *pContext,
|
||||
*(char **)buffer = addr;
|
||||
return Data_Okay;
|
||||
}
|
||||
case Valve_VirtualAddress:
|
||||
case Valve_SMAddress:
|
||||
{
|
||||
if (data->decflags & VDECODE_FLAG_BYREF)
|
||||
{
|
||||
@@ -626,7 +628,14 @@ DataStatus DecodeValveParam(IPluginContext *pContext,
|
||||
*(void **)buffer = (unsigned char *)_buffer + pCall->stackEnd + data->obj_offset;
|
||||
buffer = *(void **)buffer;
|
||||
}
|
||||
void* addr = g_pSM->FromPseudoAddress(param);
|
||||
|
||||
cell_t* sp_addr;
|
||||
if (pContext->LocalToPhysAddr(param, &sp_addr) != SP_ERROR_NONE) {
|
||||
return Data_Fail;
|
||||
}
|
||||
void* addr = (void*)(*reinterpret_cast<int64_t*>(sp_addr));
|
||||
|
||||
|
||||
if (addr == nullptr && (data->decflags & VDECODE_FLAG_ALLOWNULL) == 0)
|
||||
{
|
||||
pContext->ThrowNativeError("NULL Address not allowed");
|
||||
|
||||
@@ -53,7 +53,7 @@ enum ValveType
|
||||
Valve_Edict, /**< Edict */
|
||||
Valve_String, /**< String */
|
||||
Valve_Bool, /**< Boolean */
|
||||
Valve_VirtualAddress, /**< SM Virtual Address */
|
||||
Valve_SMAddress, /**< SM Address */
|
||||
Valve_Object, /**< Object, not matching one of the above types */
|
||||
};
|
||||
|
||||
@@ -77,15 +77,14 @@ enum DataStatus
|
||||
*/
|
||||
enum ValveCallType
|
||||
{
|
||||
ValveCall_Static, /**< Static call */
|
||||
ValveCall_Entity, /**< Thiscall (CBaseEntity implicit first parameter) */
|
||||
ValveCall_Player, /**< Thiscall (CBasePlayer implicit first parameter) */
|
||||
ValveCall_GameRules, /**< Thiscall (CGameRules implicit first paramater) */
|
||||
ValveCall_EntityList, /**< Thiscall (CGlobalEntityList implicit first paramater) */
|
||||
ValveCall_Raw, /**< Thiscall (address explicit first parameter) */
|
||||
ValveCall_Static, /**< Static call */
|
||||
ValveCall_Entity, /**< Thiscall (CBaseEntity implicit first parameter) */
|
||||
ValveCall_Player, /**< Thiscall (CBasePlayer implicit first parameter) */
|
||||
ValveCall_GameRules, /**< Thiscall (CGameRules implicit first paramater) */
|
||||
ValveCall_EntityList, /**< Thiscall (CGlobalEntityList implicit first paramater) */
|
||||
ValveCall_Raw, /**< Thiscall (address explicit first parameter) */
|
||||
ValveCall_Server, /**< Thiscall (CBaseServer implicit first parameter) */
|
||||
ValveCall_Engine, /**< Thiscall (CVEngineServer implicit first parameter) */
|
||||
ValveCall_VirtualAddress /**< Thiscall (address explicit first parameter) */
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,10 +60,9 @@ enum SDKCallType
|
||||
SDKCall_Player, /**< CBasePlayer call */
|
||||
SDKCall_GameRules, /**< CGameRules call */
|
||||
SDKCall_EntityList, /**< CGlobalEntityList call */
|
||||
SDKCall_Raw, /**< |this| pointer with an arbitrary address. This is not available if SM's virtual addresses are enabled */
|
||||
SDKCall_Raw, /**< |this| pointer with an arbitrary address. You should pass a SourceMod's Address */
|
||||
SDKCall_Server, /**< CBaseServer call */
|
||||
SDKCall_Engine, /**< CVEngineServer call */
|
||||
SDKCall_VirtualAddress /**< |this| pointer with an arbitrary SM virtual address */
|
||||
};
|
||||
|
||||
enum SDKLibrary
|
||||
@@ -90,7 +89,7 @@ enum SDKType
|
||||
SDKType_Edict, /**< edict_t (always as pointer) */
|
||||
SDKType_String, /**< NULL-terminated string (always as pointer) */
|
||||
SDKType_Bool, /**< Boolean (any) */
|
||||
SDKType_VirtualAddress, /**< SM Virtual Address */
|
||||
SDKType_Address, /**< SourceMod's Address */
|
||||
};
|
||||
|
||||
enum SDKPassMethod
|
||||
@@ -192,6 +191,7 @@ native Handle EndPrepSDKCall();
|
||||
* If the return value is a Vector or QAngles, the SECOND parameter must be a Float[3].
|
||||
* If the return value is a string, the THIRD parameter must be a String buffer, and the
|
||||
* FOURTH parameter must be the maximum length.
|
||||
* If the return value is a SourceMod's Address, the SECOND parameter must be an Address variable.
|
||||
* All parameters must be passed after the above is followed. Failure to follow these
|
||||
* rules will result in crashes or wildly unexpected behavior!
|
||||
*
|
||||
|
||||
@@ -78,6 +78,14 @@ struct Plugin
|
||||
#include <commandline>
|
||||
#include <entitylump>
|
||||
|
||||
typedef Address = int64;
|
||||
public const int64 __Int64_Address__ = 0;
|
||||
|
||||
/**< Equivallent to nullptr */
|
||||
public const int64 Address_Null = 0;
|
||||
/**< Size of a pointer in bytes (same as `sizeof(void*)`) */
|
||||
public const int64 Address_PointerSize = 0;
|
||||
|
||||
enum APLRes
|
||||
{
|
||||
APLRes_Success = 0, /**< Plugin should load */
|
||||
@@ -725,11 +733,6 @@ enum NumberType
|
||||
NumberType_Int32
|
||||
};
|
||||
|
||||
enum Address
|
||||
{
|
||||
Address_Null = 0 // a typical invalid result when an address lookup fails
|
||||
};
|
||||
|
||||
/**
|
||||
* Load up to 4 bytes from a memory address.
|
||||
*
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* =============================================================================
|
||||
* SourceMod (C)2004-2025 AlliedModders LLC. All rights reserved.
|
||||
* =============================================================================
|
||||
*
|
||||
* This file is part of the SourceMod/SourcePawn SDK.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 3.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program 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
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* As a special exception, AlliedModders LLC gives you permission to link the
|
||||
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
||||
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
||||
* by the Valve Corporation. You must obey the GNU General Public License in
|
||||
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
||||
* this exception to all derivative works. AlliedModders LLC defines further
|
||||
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
||||
* or <http://www.sourcemod.net/license.php>.
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#if defined _virtual_address_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _virtual_address_included
|
||||
|
||||
public const Address __Virtual_Address__ = view_as<Address>(0);
|
||||
public const Address PointerSize = view_as<Address>(0); /**< Size of a pointer in bytes (same as `sizeof(void*)`) */
|
||||
+6
-4
@@ -319,18 +319,20 @@ namespace SourceMod
|
||||
virtual bool IsMapRunning() = 0;
|
||||
|
||||
/**
|
||||
* @brief Converts 32-bit pseudo address to memory address on 64-bit platforms.
|
||||
* @brief DEPRECATED DO NOT USE
|
||||
* Converts 32-bit pseudo address to memory address on 64-bit platforms.
|
||||
*
|
||||
* @return Memory address, or nullptr if pseudo address could not be converted.
|
||||
*/
|
||||
virtual void *FromPseudoAddress(uint32_t pseudoAddr) = 0;
|
||||
virtual void *FromPseudoAddress(uint32_t pseudoAddr) { return nullptr; }
|
||||
|
||||
/**
|
||||
* @brief Converts memory address to 32-bit pseudo address on 64-bit platforms.
|
||||
* @brief DEPRECATED DO NOT USE
|
||||
* Converts memory address to 32-bit pseudo address on 64-bit platforms.
|
||||
*
|
||||
* @return Pseudo address, or 0 if memory address could not be converted.
|
||||
*/
|
||||
virtual uint32_t ToPseudoAddress(void *addr) = 0;
|
||||
virtual uint32_t ToPseudoAddress(void *addr) { return 0; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+1
-1
Submodule public/amtl updated: 2d3b1a3378...44e73d4862
+1
-1
Submodule sourcepawn updated: 11b22edb63...d04cd924fc
Reference in New Issue
Block a user