Raised This Month: $ Target: $400
 0% 

Orpheu: Patching strings in memory


Post New Thread Reply   
 
Thread Tools Display Modes
santuzzu
Junior Member
Join Date: May 2013
Old 11-21-2013 , 05:44   Re: Orpheu: Patching strings in memory
Reply With Quote #81

Quote:
Originally Posted by Bos93 View Post
-6 precache
thanks
santuzzu is offline
Bos93
Veteran Member
Join Date: Jul 2010
Old 11-21-2013 , 08:19   Re: Orpheu: Patching strings in memory
Reply With Quote #82

Quote:
Originally Posted by santuzzu View Post
thanks
PHP Code:
/* AMX Mod X Plugin

* (c) Copyright 2008, ConnorMcLeod 
* This file is provided as is (no warranties). 

*/ 

#include <amxmodx>
#include <fakemeta>

#define MAX_PRECACHE    812
#define MAX_FILE_LENGHT    128

new g_iCounter

new g_szPrecachedFiles[MAX_PRECACHE+1][MAX_FILE_LENGHT+1]
new 
g_szCustomFiles[MAX_PRECACHE+1][MAX_FILE_LENGHT+1]

new 
g_iForwardsIds[3]

public 
plugin_precache()
{
    
register_plugin("Precache Management""1.0.0""ConnorMcLeod")

    
g_iForwardsIds[0] = register_forward(FM_PrecacheModel"Precache_Post"1)
    
g_iForwardsIds[1] = register_forward(FM_PrecacheSound"Precache_Post"1)
    
g_iForwardsIds[2] = register_forward(FM_PrecacheGeneric"Precache_Post"1)
}

public 
plugin_natives()
{
    
register_library("precache")
    
register_native("can_precache","native_can_precache")
    
register_native("PrecacheModel","native_PrecacheModel")
    
register_native("PrecacheSound","native_PrecacheSound")
    
register_native("PrecacheGeneric","native_PrecacheGeneric")
}

public 
plugin_init()
{
    
unregister_forward(FM_PrecacheModelg_iForwardsIds[0], 1)
    
unregister_forward(FM_PrecacheSoundg_iForwardsIds[1], 1)
    
unregister_forward(FM_PrecacheGenericg_iForwardsIds[2], 1)

    new const 
szLogFile[] = "PrecacheList.log"
    
new const szLogFile2[] = "PrecacheListCust.log"
    
for(new i=1i<=MAX_PRECACHEi++)
    {
        if(
g_szPrecachedFiles[i][0])
        {
            
log_to_file(szLogFile"<%d><%s>"ig_szPrecachedFiles[i])
        }
        if(
g_szCustomFiles[i][0])
        {
            
log_to_file(szLogFile2"<%d><%s>"ig_szCustomFiles[i])
        }
    }
    
log_to_file(szLogFile"%i files precached"g_iCounter)
    
pause("ad")
}

public 
Precache_Post(const szFile[])
{
    static 
iVal
    iVal 
get_orig_retval()
    
update_counter(iVal)

    if( !
g_szPrecachedFiles[iVal][0] )
    {
        
formatex(g_szPrecachedFiles[iVal], MAX_FILE_LENGHTszFile)
    }
}

update_counter(iVal)
{
    if( 
iVal g_iCounter )
    {
        
g_iCounter iVal
        
return 1
    
}
    return 
0
}

public 
native_can_precache(iPluginiParams)
{
    return (
g_iCounter MAX_PRECACHE)
}

public 
native_PrecacheModel(iPluginiParams)
{
    if(
iParams != 1)
        return -
1

    
static szFile[MAX_FILE_LENGHT], iVal
    get_string
(1szFileMAX_FILE_LENGHT-1)

    
iVal engfunc(EngFunc_PrecacheModelszFile)

    
update_counteriVal )
    if( !
g_szCustomFiles[iVal][0] )
    {
        
formatex(g_szCustomFiles[iVal], MAX_FILE_LENGHTszFile)
    }

    return 
iVal
}

public 
native_PrecacheSound(iPluginiParams)
{
    if(
iParams != 1)
        return -
1

    
static szFile[MAX_FILE_LENGHT], iVal
    get_string
(1szFileMAX_FILE_LENGHT-1)

    
iVal engfunc(EngFunc_PrecacheSoundszFile)

    
update_counteriVal )
    if( !
g_szCustomFiles[iVal][0] )
    {
        
formatex(g_szCustomFiles[iVal], MAX_FILE_LENGHTszFile)
    }

    return 
iVal
}

public 
native_PrecacheGeneric(iPluginiParams)
{
    if(
iParams != 1)
        return -
1

    
static szFile[MAX_FILE_LENGHT], iVal
    get_string
(1szFileMAX_FILE_LENGHT-1)

    
iVal engfunc(EngFunc_PrecacheGenericszFile)

    
update_counteriVal )
    if( !
g_szCustomFiles[iVal][0] )
    {
        
formatex(g_szCustomFiles[iVal], MAX_FILE_LENGHTszFile)
    }

    return 
iVal

Bos93 is offline
Send a message via ICQ to Bos93 Send a message via Skype™ to Bos93
Old 11-21-2013, 08:29
santuzzu
This message has been deleted by santuzzu. Reason: off topic
PartialCloning
Senior Member
Join Date: Dec 2015
Old 12-13-2015 , 11:59   Re: Orpheu: Patching strings in memory
Reply With Quote #83

Quote:
Originally Posted by joaquimandrade View Post
A more useful example (replaces the sound of when you press +USE without using nothing):

Code:
{
    "name"        : "modString",
    "library"     : "mod",
    "type"        : "string",
    "memoryType"  : "data"
}
PHP Code:
    #include <amxmodx>
    #include <orpheu_memory>
    
    
public plugin_precache()
    {
        
OrpheuMemoryReplace("modString",0,"common/wpn_denyselect.wav","common/bodysplat.wav")
    } 
What if I replace a couple of strings with the same string. Is it then possible to change them back to their original value?

Also is it safe to replace the strings with empty strings if I completely want to remove the string rather than replace it?
PartialCloning is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-13-2015 , 13:35   Re: Orpheu: Patching strings in memory
Reply With Quote #84

- Just save old value and unpatch when needed.
- Depends what is the code associated to this string, if it can support empty string.
__________________
Arkshine is offline
PartialCloning
Senior Member
Join Date: Dec 2015
Old 12-13-2015 , 14:15   Re: Orpheu: Patching strings in memory
Reply With Quote #85

PHP Code:
OrpheuMemoryReplace("modString",0,"common/wpn_denyselect.wav","common/menu1.wav"
OrpheuMemoryReplace("modString",0,"common/wpn_moveselect.wav","common/menu1.wav"
PHP Code:
OrpheuMemoryReplace("modString",0,"#Terrorists_Win"" "); 
1. How would I unpatch that? I can't reverse it because I have two 'common/menu1.wav's now. Unless you meant something else by "save old value".

2. In that case it's even worse, how would I change it back now that it's an empty string?
PartialCloning is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-13-2015 , 15:04   Re: Orpheu: Patching strings in memory
Reply With Quote #86

You can retrieve the last address patched, as last param, if I remember well.
But since you want infinite replacement, you will likely need to OrpheuMemoryReplaceAtAddress, so you can loop from last patched address + 4, if you see what I mean.
__________________

Last edited by Arkshine; 12-14-2015 at 06:17.
Arkshine is offline
PartialCloning
Senior Member
Join Date: Dec 2015
Old 12-14-2015 , 06:17   Re: Orpheu: Patching strings in memory
Reply With Quote #87

The include does not mention anything about the last parameter. These functions are not documented well, you should consider updating the includes at some point. For example "OrpheuMemoryReplaceAtAddress" only brings 18 results from alliedmods on google.

Using the last parm value I was able to unpatch it using OrpheuMemoryReplaceAtAddress after originally setting it using OrpheuMemoryReplace. Is that a good/correct way to do it?

Also can you elaborate more on the last part? What do you mean by "you can loop passing last patched address + 4"? What's the 4 doing there and what's the loop for?
PartialCloning is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-14-2015 , 07:20   Re: Orpheu: Patching strings in memory
Reply With Quote #88

I don't know why joaquim did not document it from the start. I think you can find reference on this forum, but yeah include should add a note about it.

If you know the address, you should probably use directly OrpheuMemorySetAtAddress, more straight, but probably doesn't matter that much using OrpheuMemoryReplaceAtAddress as long the count is set to 1.

In your previous you're using count at 0, meaning replacing all found strings.
If you want to keep track of where memory has been patched, you will need to loop and saving address.
Like (totally unchecked):

EDIT: The following would be just the safe way because you know the address before patched and restore string no matter what is current content. I'm showing you just for the sake to understand.
You could actually probably just OrpheuMemoryReplace with reversed string like : OrpheuMemoryReplace("modString",0,"common/menu1.wav", "common/wpn_denyselect.wav") ; it should work too.

Code:
new Array:addressesList = ArrayCreate(); new const originalString[]   = "common/wpn_denyselect.wav"; new const replacedString[]   = "common/menu1.wav"; new const memoryIdentifier[] = "modString"; const replacementCount = 1; new startAddress = OrpheuGetLibraryAddress("mod"); new lastAddress; // PATCH   while (OrpheuMemoryReplaceAtAddress(startAddress, memoryIdentifier, replacementCount, originalString, replacedString, lastAddress)) {     startAddress = lastAddress + sizeof(originalString); // Said +4 because thought by default of an address which on 4 bytes. Here size of string, though it's not really needed.     ArrayPushCell(addressesList, lastAddress); } // UNPATCH for (new i = 0, size = ArraySize(addressesList); i < size; ++i) {     OrpheuMemorySetAtAddress(ArrayGetCell(addressesList, i), memoryIdentifier, replacementCount, originalString); }
__________________

Last edited by Arkshine; 12-14-2015 at 08:10.
Arkshine is offline
PartialCloning
Senior Member
Join Date: Dec 2015
Old 12-15-2015 , 01:11   Re: Orpheu: Patching strings in memory
Reply With Quote #89

Alright thank you. It's currently giving me an error when trying to unpatch,
PHP Code:
[AMXXRun time error 10native error (native "OrpheuMemorySetAtAddress")
[
ORPHEUTo use this functionality you must provide valid identifiers for the memory 
However at least now I have something to work with and I'll see if I can figure it out by printing values and seeing how other plugins use that function.

Also upon re-reading the oprheu_memory include, it does mention on some of the natives that "You can give an extra argument to retrieve the address where the data retrieved lies".
PartialCloning is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:59.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode