diff --git a/core/logic/smn_core.cpp b/core/logic/smn_core.cpp index fd21e3a51e..6065d7230d 100644 --- a/core/logic/smn_core.cpp +++ b/core/logic/smn_core.cpp @@ -1024,203 +1024,6 @@ static cell_t StoreAddressToAddress(IPluginContext *pContext, const cell_t *para return 0; } -template -static inline void AddressMemcpy(T* dest, U* src, cell_t len) -{ - for (; len; dest++, src++, len--) - { - *dest = *src; - } -} - -static cell_t LoadBytesFromAddress(IPluginContext *pContext, const cell_t *params) -{ - cell_t offset = params[4]; - -#ifdef PLATFORM_X86 - int8_t *addr = reinterpret_cast(params[1]) + offset; -#else - int8_t *addr = reinterpret_cast(pseudoAddr.FromPseudoAddress(params[1])) + offset; -#endif - - if (addr == NULL) - { - return pContext->ThrowNativeError("Address cannot be null"); - } - else if (reinterpret_cast(addr) < VALID_MINIMUM_MEMORY_ADDRESS) - { - return pContext->ThrowNativeError("Invalid address 0x%x is pointing to reserved memory.", addr); - } - - cell_t* chunks = nullptr; - pContext->LocalToPhysAddr(params[2], &chunks); - cell_t len = params[3]; - if (len <= 0) - { - return pContext->ThrowNativeError("Chunks array length must be positive!"); - } - - AddressMemcpy(chunks, addr, len); - return 0; -} - -static cell_t StoreBytesToAddress(IPluginContext *pContext, const cell_t *params) -{ - cell_t offset = params[5]; - -#ifdef PLATFORM_X86 - int8_t *addr = reinterpret_cast(params[1]) + offset; -#else - int8_t *addr = reinterpret_cast(pseudoAddr.FromPseudoAddress(params[1])) + offset; -#endif - - if (addr == NULL) - { - return pContext->ThrowNativeError("Address cannot be null"); - } - else if (reinterpret_cast(addr) < VALID_MINIMUM_MEMORY_ADDRESS) - { - return pContext->ThrowNativeError("Invalid address 0x%x is pointing to reserved memory.", addr); - } - - cell_t* chunks = nullptr; - pContext->LocalToPhysAddr(params[2], &chunks); - cell_t len = params[3]; - if (len <= 0) - { - return pContext->ThrowNativeError("Chunks array length must be positive!"); - } - - if (params[4]) - { - SourceHook::SetMemAccess(addr, len, SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC); - } - - AddressMemcpy(addr, chunks, len); - return 0; -} - -static cell_t LoadSpanFromAddress(IPluginContext *pContext, const cell_t *params) -{ - cell_t offset = params[5]; - -#ifdef PLATFORM_X86 - void *addr = reinterpret_cast(reinterpret_cast(params[1]) + offset); -#else - void *addr = reinterpret_cast(reinterpret_cast(pseudoAddr.FromPseudoAddress(params[1])) + offset); -#endif - - if (addr == NULL) - { - return pContext->ThrowNativeError("Address cannot be null"); - } - else if (reinterpret_cast(addr) < VALID_MINIMUM_MEMORY_ADDRESS) - { - return pContext->ThrowNativeError("Invalid address 0x%x is pointing to reserved memory.", addr); - } - - cell_t* chunks = nullptr; - pContext->LocalToPhysAddr(params[2], &chunks); - cell_t len = params[3]; - if (len <= 0) - { - return pContext->ThrowNativeError("Chunks array length must be positive!"); - } - - NumberType size = static_cast(params[4]); - - switch(size) - { - case NumberType_Int8: - AddressMemcpy(chunks, reinterpret_cast(addr), len); - break; - case NumberType_Int16: - AddressMemcpy(chunks, reinterpret_cast(addr), len); - break; - case NumberType_Int32: - AddressMemcpy(chunks, reinterpret_cast(addr), len); - break; - default: - return pContext->ThrowNativeError("Invalid number types %d", size); - } - return 0; -} - -static cell_t StoreSpanToAddress(IPluginContext *pContext, const cell_t *params) -{ - cell_t offset = params[6]; - -#ifdef PLATFORM_X86 - void *addr = reinterpret_cast(reinterpret_cast(params[1]) + offset); -#else - void *addr = reinterpret_cast(reinterpret_cast(pseudoAddr.FromPseudoAddress(params[1])) + offset); -#endif - - if (addr == NULL) - { - return pContext->ThrowNativeError("Address cannot be null"); - } - else if (reinterpret_cast(addr) < VALID_MINIMUM_MEMORY_ADDRESS) - { - return pContext->ThrowNativeError("Invalid address 0x%x is pointing to reserved memory.", addr); - } - - cell_t* chunks = nullptr; - pContext->LocalToPhysAddr(params[2], &chunks); - cell_t len = params[3]; - if (len <= 0) - { - return pContext->ThrowNativeError("Chunks array length must be positive!"); - } - - NumberType size = static_cast(params[4]); - - switch(size) - { - case NumberType_Int8: - if (params[5]) - { - SourceHook::SetMemAccess(addr, len * sizeof(int8_t), SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC); - } - AddressMemcpy(reinterpret_cast(addr), chunks, len); - break; - case NumberType_Int16: - if (params[5]) - { - SourceHook::SetMemAccess(addr, len * sizeof(int16_t), SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC); - } - AddressMemcpy(reinterpret_cast(addr), chunks, len); - break; - case NumberType_Int32: - if (params[5]) - { - SourceHook::SetMemAccess(addr, len * sizeof(int32_t), SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC); - } - AddressMemcpy(reinterpret_cast(addr), chunks, len); - break; - default: - return pContext->ThrowNativeError("Invalid number types %d", size); - } - - return 0; -} - -static cell_t OffsetAddress(IPluginContext *pContext, const cell_t *params) -{ -#ifdef PLATFORM_X86 - int8_t *addr = reinterpret_cast(params[1]); -#else - int8_t *addr = reinterpret_cast(pseudoAddr.FromPseudoAddress(params[1])); -#endif - - cell_t offset = params[2]; -#ifdef PLATFORM_X86 - return reinterpret_cast(addr + offset); -#else - return pseudoAddr.ToPseudoAddress(addr + offset); -#endif -} - static cell_t IsNullVector(IPluginContext *pContext, const cell_t *params) { cell_t *pNullVec = pContext->GetNullRef(SP_NULL_VECTOR); @@ -1430,11 +1233,6 @@ REGISTER_NATIVES(coreNatives) {"StoreToAddress", StoreToAddress}, {"LoadAddressFromAddress", LoadAddressFromAddress}, {"StoreAddressToAddress", StoreAddressToAddress}, - {"LoadBytesFromAddress ", LoadBytesFromAddress}, - {"StoreBytesToAddress", StoreBytesToAddress}, - {"LoadSpanFromAddress ", LoadSpanFromAddress}, - {"StoreSpanToAddress", StoreSpanToAddress}, - {"OffsetAddress", OffsetAddress}, {"IsNullVector", IsNullVector}, {"IsNullString", IsNullString}, {"LogStackTrace", LogStackTrace}, diff --git a/plugins/include/sourcemod.inc b/plugins/include/sourcemod.inc index db5d3aeba1..e97e231c0c 100644 --- a/plugins/include/sourcemod.inc +++ b/plugins/include/sourcemod.inc @@ -736,7 +736,7 @@ enum Address * @param addr Address to a memory location. * @param size How many bytes should be read. * If loading a floating-point value, use NumberType_Int32. - * @param offset Amount of bytes the addr parameter needs to be offsetted by. + * @param offset Amount of bytes the base address needs to be offsetted by before loading. * @return The value that is stored at that address. * @error Address is null or pointing to reserved memory. */ @@ -751,7 +751,7 @@ native any LoadFromAddress(Address addr, NumberType size, int offset = 0); * If storing a floating-point value, use NumberType_Int32. * @param updateMemAccess If true, SourceMod will set read / write / exec permissions * on the memory page being written to. - * @param offset Amount of bytes the addr parameter needs to be offsetted by. + * @param offset Amount of bytes the base address needs to be offsetted by before storing. * @error Address is null or pointing to reserved memory. */ native void StoreToAddress(Address addr, any data, NumberType size, bool updateMemAccess = true, int offset = 0); @@ -760,8 +760,8 @@ native void StoreToAddress(Address addr, any data, NumberType size, bool updateM * Load an address value from a memory address. * * @param addr Address to a memory location. + * @param offset Amount of bytes the base address needs to be offsetted by before loading. * @return The address value that is stored at that address. - * @param offset Amount of bytes the addr parameter needs to be offsetted by. * @error Address is null or pointing to reserved memory. */ native Address LoadAddressFromAddress(Address addr, int offset = 0); @@ -773,70 +773,11 @@ native Address LoadAddressFromAddress(Address addr, int offset = 0); * @param data Address value to store at the address. * @param updateMemAccess If true, SourceMod will set read / write / exec permissions * on the memory page being written to. - * @param offset Amount of bytes the addr parameter needs to be offsetted by. + * @param offset Amount of bytes the base address needs to be offsetted by before storing. * @error Address is null or pointing to reserved memory. */ native void StoreAddressToAddress(Address addr, Address data, bool updateMemAccess = true, int offset = 0); -/** - * Load up to (len) bytes from a memory address. - * - * @param addr Address to a memory location. - * @param bytes Array bytes to load. - * @param len How many bytes should be read. - * @param offset Amount of bytes the addr parameter needs to be offsetted by. - * @error Address is null or pointing to reserved memory. Bytes array length is null or negative. - */ -native void LoadBytesFromAddress(Address addr, char[] bytes, int len, int offset = 0); - -/** - * Store up to (len) bytes to a memory address. - * - * @param addr Address to a memory location. - * @param bytes Array of bytes to store. - * @param len How many bytes should be written. - * @param updateMemAccess If true, SourceMod will set read / write / exec permissions - * on the memory page being written to. - * @param offset Amount of bytes the addr parameter needs to be offsetted by. - * @error Address is null or pointing to reserved memory. Bytes array length is null or negative. - */ -native void StoreBytesToAddress(Address addr, char[] bytes, int len, bool updateMemAccess = true, int offset = 0); - -/** - * Load a sized span from a memory address. - * - * @param addr Address to a memory location. - * @param span Array of NumberType sized values that constitute the span. - * @param len Size of the span. - * @param size Size of each element. - * @param offset Amount of bytes the addr parameter needs to be offsetted by. - * @error Address is null or pointing to reserved memory. Span length is null or negative. - */ -native void LoadSpanFromAddress(Address addr, any[] span, int len, NumberType size, int offset = 0); - -/** - * Store a given sized span to the given address. - * - * @param addr Address to a memory location. - * @param span Array of NumberType sized values that constitute the span. - * @param len Size of the span. - * @param size Size of each element. - * @param updateMemAccess If true, SourceMod will set read / write / exec permissions - * on the memory page being written to. - * @param offset Amount of bytes the addr parameter needs to be offsetted by. - * @error Address is null or pointing to reserved memory. Span length is null or negative. - */ -native void StoreSpanToAddress(Address addr, any[] span, int len, NumberType size, bool updateMemAccess = true, int offset = 0); - -/** - * Offsets the given memory address. - * - * @param address Address to a memory location. - * @param offset How many bytes we should offset the address parameter by. - * @return The offsetted memory address. - */ -native Address OffsetAddress(Address addr, int offset); - methodmap FrameIterator < Handle { // Creates a stack frame iterator to build your own stack traces. // @return New handle to a FrameIterator.