@@ -892,7 +892,6 @@ static cell_t LoadFromAddress(IPluginContext *pContext, const cell_t *params)
892892 }
893893}
894894
895-
896895static cell_t StoreToAddress (IPluginContext *pContext, const cell_t *params)
897896{
898897 void *addr = reinterpret_cast <void *>(params[1 ]);
@@ -949,6 +948,60 @@ static cell_t StoreToAddress(IPluginContext *pContext, const cell_t *params)
949948 return 0 ;
950949}
951950
951+ static cell_t LoadAddressFromAddress (IPluginContext *pContext, const cell_t *params)
952+ {
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 ]);
956+ }
957+
958+ if (addr == NULL )
959+ {
960+ return pContext->ThrowNativeError (" Address cannot be null" );
961+ }
962+ else if (reinterpret_cast <uintptr_t >(addr) < VALID_MINIMUM_MEMORY_ADDRESS)
963+ {
964+ return pContext->ThrowNativeError (" Invalid address 0x%x is pointing to reserved memory." , addr);
965+ }
966+
967+ void * data = *reinterpret_cast <void **>(addr);
968+ if (pContext->GetRuntime ()->FindPubvarByName (" __Virtual_Address__" , nullptr ) != SP_ERROR_NONE) {
969+ return pseudoAddr.ToPseudoAddress (data);
970+ }
971+ return (cell_t )data;
972+ }
973+
974+ static cell_t StoreAddressToAddress (IPluginContext *pContext, const cell_t *params)
975+ {
976+ void *addr = reinterpret_cast <void *>(params[1 ]);
977+ if (pContext->GetRuntime ()->FindPubvarByName (" __Virtual_Address__" , nullptr ) != SP_ERROR_NONE) {
978+ addr = pseudoAddr.FromPseudoAddress (params[1 ]);
979+ }
980+
981+ if (addr == NULL )
982+ {
983+ return pContext->ThrowNativeError (" Address cannot be null" );
984+ }
985+ else if (reinterpret_cast <uintptr_t >(addr) < VALID_MINIMUM_MEMORY_ADDRESS)
986+ {
987+ return pContext->ThrowNativeError (" Invalid address 0x%x is pointing to reserved memory." , addr);
988+ }
989+
990+ void *data = reinterpret_cast <void *>(params[2 ]);
991+ if (pContext->GetRuntime ()->FindPubvarByName (" __Virtual_Address__" , nullptr ) != SP_ERROR_NONE) {
992+ data = pseudoAddr.FromPseudoAddress (params[2 ]);
993+ }
994+
995+ bool updateMemAccess = params[3 ];
996+
997+ if (updateMemAccess) {
998+ SourceHook::SetMemAccess (addr, sizeof (void *), SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC);
999+ }
1000+ *reinterpret_cast <void **>(addr) = data;
1001+
1002+ return 0 ;
1003+ }
1004+
9521005static cell_t IsNullVector (IPluginContext *pContext, const cell_t *params)
9531006{
9541007 cell_t *pNullVec = pContext->GetNullRef (SP_NULL_VECTOR);
@@ -1156,6 +1209,8 @@ REGISTER_NATIVES(coreNatives)
11561209 {" RequireFeature" , RequireFeature},
11571210 {" LoadFromAddress" , LoadFromAddress},
11581211 {" StoreToAddress" , StoreToAddress},
1212+ {" LoadAddressFromAddress" , LoadAddressFromAddress},
1213+ {" StoreAddressToAddress" , StoreAddressToAddress},
11591214 {" IsNullVector" , IsNullVector},
11601215 {" IsNullString" , IsNullString},
11611216 {" LogStackTrace" , LogStackTrace},
0 commit comments