mirror of
https://github.com/alliedmodders/sourcemod.git
synced 2025-12-07 10:28:34 +00:00
Some checks failed
Continuous Integration / ${{ matrix.os_short }}-${{ matrix.compiler_cc }} (clang, clang++, ubuntu-latest, linux) (push) Has been cancelled
Continuous Integration / ${{ matrix.os_short }}-${{ matrix.compiler_cc }} (clang-14, clang++-14, ubuntu-22.04, linux) (push) Has been cancelled
Continuous Integration / ${{ matrix.os_short }}-${{ matrix.compiler_cc }} (msvc, windows-latest, win) (push) Has been cancelled
hl2sdk-mock tests / mock (push) Has been cancelled
SourcePawn scripting / build (ubuntu-latest, linux) (push) Has been cancelled
SourcePawn scripting / build (windows-latest, win) (push) Has been cancelled
In the current ongoing effort for sourcemod to fully support 64 bits, we are introducing "virtual address".
# Explanation
Because SourcePawn does not yet support a 64 bits-wide type it's been impossible for any plugins to hold addresses in regular 32-bits wide variable.
A first attempt at solving this issue was made in commit ce1a4dcac0 therein dubbed "PseudoAddress", however this turned out to be an unsatisfactory solution, as any 'high' address if offsetted could turn invalid (or outright be impossible to map).
This leaves us with three alternatives :
- New type
- Convert Address into a handle
- Virtual Address
A new type is the most destructive solution, as it entails breaking every single Address related method. While that solution is still not off the table, we're reserving it as the last attempt should this commit fail.
Converting into a handle type is a good compromise between a brand new type whilst also preserving the Address methods. However, this comes with two issues: the first being that you can no longer offset Address, the second is that we would require authors to free the handle type which will be very confusing. This will likely not be implemented.
# Virtual address
Under a reasonable assumption, we've noted that the average plugin is unlikely to play with more than 4 GB of memory; this shouldn't be too surprising as all valve games were once 32bits and therefore limited to 4GB. Assuming this stays mostly true and a plugin isn't interested with the mapped memory of lesser known modules (like soundlib or matlib), it is fair to assume plugins are unlikely to access more than 4GB of mapped memory. Working with this in mind, we map the memory the plugins are likely to access to our custom virtual address ranges (from 0 to 4Gb, the values of which can fit on 32bits variable). If any memory was missed and plugins were to try an access it later those ranges will be late-mapped to our virtual address ranges until we run out of them.
In order to use virtual addressing, whether on 32 bits or 64 bits. Plugins must now "#include <virtual_address>", as well as use the new SDKCall_VirtualAddress, SDKType_VirtualAddress, LoadAddressFromAddress & StoreAddressToAddress where it's appropriate to.
158 lines
5.5 KiB
C++
158 lines
5.5 KiB
C++
/**
|
|
* vim: set ts=4 :
|
|
* =============================================================================
|
|
* SourceMod SDKTools Extension
|
|
* Copyright (C) 2004-2008 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>.
|
|
*
|
|
* Version: $Id$
|
|
*/
|
|
|
|
#ifndef _INCLUDE_SOURCEMOD_VDECODER_H_
|
|
#define _INCLUDE_SOURCEMOD_VDECODER_H_
|
|
|
|
#include <sm_platform.h>
|
|
#include <sp_vm_api.h>
|
|
#include <extensions/IBinTools.h>
|
|
|
|
using namespace SourceMod;
|
|
using namespace SourcePawn;
|
|
|
|
/**
|
|
* @brief Encapsulates types from the SDK
|
|
*/
|
|
enum ValveType
|
|
{
|
|
Valve_CBaseEntity, /**< CBaseEntity */
|
|
Valve_CBasePlayer, /**< CBasePlayer (disallow normal ents) */
|
|
Valve_Vector, /**< Vector */
|
|
Valve_QAngle, /**< QAngle */
|
|
Valve_POD, /**< Plain old data, int32 size */
|
|
Valve_Float, /**< Float */
|
|
Valve_Edict, /**< Edict */
|
|
Valve_String, /**< String */
|
|
Valve_Bool, /**< Boolean */
|
|
Valve_VirtualAddress, /**< SM Virtual Address */
|
|
Valve_Object, /**< Object, not matching one of the above types */
|
|
};
|
|
|
|
enum DataStatus
|
|
{
|
|
Data_Fail = 0,
|
|
Data_Okay = 1,
|
|
};
|
|
|
|
#define VDECODE_FLAG_ALLOWNULL (1<<0) /**< Allow NULL for pointers */
|
|
#define VDECODE_FLAG_ALLOWNOTINGAME (1<<1) /**< Allow players not in game */
|
|
#define VDECODE_FLAG_ALLOWWORLD (1<<2) /**< Allow World entity */
|
|
#define VDECODE_FLAG_BYREF (1<<3) /**< Floats/ints by reference */
|
|
|
|
#define VENCODE_FLAG_COPYBACK (1<<0) /**< Copy back data */
|
|
|
|
#define PASSFLAG_ASPOINTER (1<<30) /**< Not an actual passflag, used internally */
|
|
|
|
/**
|
|
* @brief Valve pre-defined calling types
|
|
*/
|
|
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_Server, /**< Thiscall (CBaseServer implicit first parameter) */
|
|
ValveCall_Engine, /**< Thiscall (CVEngineServer implicit first parameter) */
|
|
ValveCall_VirtualAddress /**< Thiscall (address explicit first parameter) */
|
|
};
|
|
|
|
/**
|
|
* @brief Valve parameter info
|
|
*/
|
|
struct ValvePassInfo
|
|
{
|
|
ValveType vtype; /**< IN: Valve type */
|
|
unsigned int decflags; /**< IN: VDECODE_FLAG_* */
|
|
unsigned int encflags; /**< IN: VENCODE_FLAG_* */
|
|
PassType type; /**< IN: Pass information */
|
|
unsigned int flags; /**< IN: Pass flags */
|
|
size_t offset; /**< OUT: stack offset */
|
|
size_t obj_offset; /**< OUT: object offset at end of the stack */
|
|
};
|
|
|
|
struct ValveCall;
|
|
|
|
/**
|
|
* @brief Converts a valve parameter to a bintools parameter.
|
|
*
|
|
* @param type Valve type.
|
|
* @param pass Either basic or object.
|
|
* @param flags Either BYVAL or BYREF.
|
|
* @param info Buffer to store param info in.
|
|
* @return Number of bytes this will use in the virtual stack,
|
|
* or 0 if conversion was impossible.
|
|
*/
|
|
size_t ValveParamToBinParam(ValveType type,
|
|
PassType pass,
|
|
unsigned int flags,
|
|
PassInfo *info,
|
|
bool &needs_extra);
|
|
|
|
/**
|
|
* @brief Decodes data from a plugin to native data.
|
|
*
|
|
* Note: If you're going to return false, make sure to
|
|
* throw an error.
|
|
*
|
|
* @param pContext Plugin context.
|
|
* @param param Parameter value from params array.
|
|
* @param buffer Buffer space in the virutal stack.
|
|
* @return True on success, false otherwise.
|
|
*/
|
|
DataStatus DecodeValveParam(IPluginContext *pContext,
|
|
cell_t param,
|
|
const ValveCall *pCall,
|
|
const ValvePassInfo *vdata,
|
|
void *buffer);
|
|
|
|
/**
|
|
* @brief Encodes native data back into a plugin.
|
|
*
|
|
* Note: If you're going to return false, make sure to
|
|
* throw an error.
|
|
*
|
|
* @param pContext Plugin context.
|
|
* @param param Parameter value from params array.
|
|
* @param buffer Buffer space in the virutal stack.
|
|
* @return True on success, false otherwise.
|
|
*/
|
|
DataStatus EncodeValveParam(IPluginContext *pContext,
|
|
cell_t param,
|
|
const ValveCall *pCall,
|
|
const ValvePassInfo *vdata,
|
|
const void *buffer);
|
|
|
|
#endif //_INCLUDE_SOURCEMOD_VDECODER_H_
|