Skip to content

Commit 2b5554a

Browse files
authored
Make Address a int64 if <virtual_address> is included (#2407)
1 parent 2e395c6 commit 2b5554a

24 files changed

Lines changed: 224 additions & 300 deletions

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,3 @@
1212
[submodule "public/safetyhook"]
1313
path = public/safetyhook
1414
url = https://github.com/alliedmodders/safetyhook
15-
[submodule "core/logic/libaddrz"]
16-
path = core/logic/libaddrz
17-
url = https://github.com/dvander/libaddrz.git

bridge/include/LogicProvider.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ struct sm_logic_t
7171
void (*RegisterProfiler)(IProfilingTool *tool);
7272
ICellArray * (*CreateCellArray)(size_t blocksize);
7373
void (*FreeCellArray)(ICellArray *arr);
74-
void * (*FromPseudoAddress)(uint32_t pseudoAddr);
75-
uint32_t (*ToPseudoAddress)(void *addr);
7674
void (*SetEntityLumpWritable)(bool writable);
7775
bool (*ParseEntityLumpString)(const char *entityString, int &status, size_t &position);
7876
const char * (*GetEntityLumpString)();

core/logic/AMBuilder

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,7 @@ for cxx in builder.targets:
8585
'FrameIterator.cpp',
8686
'DatabaseConfBuilder.cpp',
8787
'LumpManager.cpp',
88-
'smn_entitylump.cpp',
89-
'libaddrz/addrz.cpp',
90-
'libaddrz/mapping.cpp',
91-
'libaddrz/platform.cpp',
92-
'libaddrz/proc_maps.cpp',
93-
'PseudoAddrManager.cpp',
88+
'smn_entitylump.cpp'
9489
]
95-
if binary.compiler.target.platform == 'linux':
96-
binary.sources += ['libaddrz/platform_linux.cpp']
97-
elif binary.compiler.target.platform == 'windows':
98-
binary.sources += ['libaddrz/platform_windows.cpp']
9990

10091
SM.binaries += [builder.Add(binary)]

core/logic/PseudoAddrManager.cpp

Lines changed: 0 additions & 123 deletions
This file was deleted.

core/logic/PseudoAddrManager.h

Lines changed: 0 additions & 48 deletions
This file was deleted.

core/logic/common_logic.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
#include "RootConsoleMenu.h"
5858
#include "CellArray.h"
5959
#include "smn_entitylump.h"
60-
#include "PseudoAddrManager.h"
6160
#include <bridge/include/BridgeAPI.h>
6261
#include <bridge/include/IProviderCallbacks.h>
6362

@@ -87,7 +86,6 @@ IScriptManager *scripts = &g_PluginSys;
8786
IExtensionSys *extsys = &g_Extensions;
8887
ILogger *logger = &g_Logger;
8988
CNativeOwner g_CoreNatives;
90-
PseudoAddressManager pseudoAddr;
9189

9290
EntityLumpParseResult lastParseResult;
9391

@@ -119,16 +117,6 @@ static void RegisterProfiler(IProfilingTool *tool)
119117
g_ProfileToolManager.RegisterTool(tool);
120118
}
121119

122-
static void *FromPseudoAddress(uint32_t paddr)
123-
{
124-
return pseudoAddr.FromPseudoAddress(paddr);
125-
}
126-
127-
static uint32_t ToPseudoAddress(void *addr)
128-
{
129-
return pseudoAddr.ToPseudoAddress(addr);
130-
}
131-
132120
static void SetEntityLumpWritable(bool writable)
133121
{
134122
g_bLumpAvailableForWriting = writable;
@@ -191,8 +179,6 @@ static sm_logic_t logic =
191179
RegisterProfiler,
192180
CellArray::New,
193181
CellArray::Free,
194-
FromPseudoAddress,
195-
ToPseudoAddress,
196182
SetEntityLumpWritable,
197183
ParseEntityLumpString,
198184
GetEntityLumpString,
@@ -227,7 +213,6 @@ static void logic_init(CoreProvider* core, sm_logic_t* _logic)
227213
g_pSourcePawn2 = *core->spe2;
228214
SMGlobalClass::head = core->listeners;
229215

230-
pseudoAddr.Initialize();
231216
g_ShareSys.Initialize();
232217
g_pCoreIdent = g_ShareSys.CreateCoreIdentity();
233218

core/logic/common_logic.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
#define _INCLUDE_SOURCEMOD_COMMON_LOGIC_H_
3434

3535
#include "../sm_globals.h"
36-
#ifdef KE_ARCH_X64
37-
#include "PseudoAddrManager.h"
38-
#endif
3936

4037
namespace SourceMod {
4138
class CoreProvider;
@@ -60,7 +57,6 @@ class IVEngineServerBridge;
6057
#endif
6158
} // namespace SourceMod
6259
struct ServerGlobals;
63-
class PseudoAddressManager;
6460

6561
extern SourceMod::CoreProvider *bridge;
6662
extern SourceMod::IHandleSys *handlesys;
@@ -80,7 +76,6 @@ extern SourceMod::IScriptManager *scripts;
8076
extern SourceMod::IExtensionSys *extsys;
8177
extern SourceMod::ILogger *logger;
8278
extern SourceMod::IMenuManager *menus;
83-
extern PseudoAddressManager pseudoAddr;
8479

8580
#if defined SM_LOGIC
8681
extern SourceMod::IVEngineServerBridge *engine;

core/logic/libaddrz

Lines changed: 0 additions & 1 deletion
This file was deleted.

core/logic/smn_core.cpp

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
#include <bridge/include/CoreProvider.h>
6060
#include <bridge/include/IScriptManager.h>
6161
#include <bridge/include/IExtensionBridge.h>
62-
#include "PseudoAddrManager.h"
6362
#include <sh_vector.h>
6463

6564
using namespace SourceMod;
@@ -865,8 +864,13 @@ enum NumberType
865864
static cell_t LoadFromAddress(IPluginContext *pContext, const cell_t *params)
866865
{
867866
void *addr = reinterpret_cast<void*>(params[1]);
868-
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
869-
addr = pseudoAddr.FromPseudoAddress(params[1]);
867+
if (pContext->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
868+
cell_t* sp_addr;
869+
if (int err = pContext->LocalToPhysAddr(params[1], &sp_addr); err != SP_ERROR_NONE) {
870+
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
871+
}
872+
auto value = *reinterpret_cast<int64_t*>(sp_addr);
873+
addr = (void*)value;
870874
}
871875

872876
if (addr == NULL)
@@ -895,8 +899,13 @@ static cell_t LoadFromAddress(IPluginContext *pContext, const cell_t *params)
895899
static cell_t StoreToAddress(IPluginContext *pContext, const cell_t *params)
896900
{
897901
void *addr = reinterpret_cast<void*>(params[1]);
898-
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
899-
addr = pseudoAddr.FromPseudoAddress(params[1]);
902+
if (pContext->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
903+
cell_t* sp_addr;
904+
if (int err = pContext->LocalToPhysAddr(params[1], &sp_addr); err != SP_ERROR_NONE) {
905+
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
906+
}
907+
auto value = *reinterpret_cast<int64_t*>(sp_addr);
908+
addr = (void*)value;
900909
}
901910

902911
if (addr == NULL)
@@ -950,9 +959,19 @@ static cell_t StoreToAddress(IPluginContext *pContext, const cell_t *params)
950959

951960
static cell_t LoadAddressFromAddress(IPluginContext *pContext, const cell_t *params)
952961
{
953-
void *addr = reinterpret_cast<void*>(params[1]);
954-
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
955-
addr = pseudoAddr.FromPseudoAddress(params[1]);
962+
cell_t shift_param = 0;
963+
if (pContext->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
964+
shift_param = 1;
965+
}
966+
967+
void *addr = reinterpret_cast<void*>(params[shift_param + 1]);
968+
if (shift_param != 0) {
969+
cell_t* sp_addr;
970+
if (int err = pContext->LocalToPhysAddr(params[shift_param + 1], &sp_addr); err != SP_ERROR_NONE) {
971+
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
972+
}
973+
auto value = *reinterpret_cast<int64_t*>(sp_addr);
974+
addr = (void*)value;
956975
}
957976

958977
if (addr == NULL)
@@ -963,19 +982,28 @@ static cell_t LoadAddressFromAddress(IPluginContext *pContext, const cell_t *par
963982
{
964983
return pContext->ThrowNativeError("Invalid address 0x%x is pointing to reserved memory.", addr);
965984
}
966-
967985
void* data = *reinterpret_cast<void**>(addr);
968-
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
969-
return pseudoAddr.ToPseudoAddress(data);
986+
987+
if (shift_param != 0) {
988+
cell_t* sp_addr;
989+
if (int err = pContext->LocalToPhysAddr(params[1], &sp_addr); err != SP_ERROR_NONE) {
990+
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
991+
}
992+
*reinterpret_cast<int64_t*>(sp_addr) = reinterpret_cast<uintptr_t>(data);
970993
}
971994
return reinterpret_cast<uintptr_t>(data);
972995
}
973996

974997
static cell_t StoreAddressToAddress(IPluginContext *pContext, const cell_t *params)
975998
{
976999
void *addr = reinterpret_cast<void*>(params[1]);
977-
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
978-
addr = pseudoAddr.FromPseudoAddress(params[1]);
1000+
if (pContext->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
1001+
cell_t* sp_addr;
1002+
if (int err = pContext->LocalToPhysAddr(params[1], &sp_addr); err != SP_ERROR_NONE) {
1003+
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
1004+
}
1005+
auto value = *reinterpret_cast<int64_t*>(sp_addr);
1006+
addr = (void*)value;
9791007
}
9801008

9811009
if (addr == NULL)
@@ -988,8 +1016,13 @@ static cell_t StoreAddressToAddress(IPluginContext *pContext, const cell_t *para
9881016
}
9891017

9901018
void *data = reinterpret_cast<void*>(params[2]);
991-
if (pContext->GetRuntime()->FindPubvarByName("__Virtual_Address__", nullptr) == SP_ERROR_NONE) {
992-
data = pseudoAddr.FromPseudoAddress(params[2]);
1019+
if (pContext->GetRuntime()->FindPubvarByName("__Int64_Address__", nullptr) == SP_ERROR_NONE) {
1020+
cell_t* sp_addr;
1021+
if (int err = pContext->LocalToPhysAddr(params[2], &sp_addr); err != SP_ERROR_NONE) {
1022+
return pContext->ThrowNativeErrorEx(err, "Could not read argument");
1023+
}
1024+
auto value = *reinterpret_cast<int64_t*>(sp_addr);
1025+
data = (void*)value;
9931026
}
9941027

9951028
bool updateMemAccess = params[3];

0 commit comments

Comments
 (0)