AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   New Plugin Submissions (https://forums.alliedmods.net/forumdisplay.php?f=26)
-   -   Entity Resources Replacement[ V 1.4 ] (https://forums.alliedmods.net/showthread.php?t=250244)

HamletEagle 10-20-2014 14:18

Entity Resources Replacement[ V 1.4 ]
 
3 Attachment(s)

Entity Resources Replacement 1.4
Release: 20.10.2014 | Last Update: 29.06.2016

IF YOU ARE UPDATING FROM VERSION 1.3: REMOVE YOUR OLD CONFIGURATION FILES AND DOWNLOAD NEW ONES(INSIDE ARCHIVE). THEY WERE REWRITTEN, ALSO A TYPO IN DYNAMIC REPLACEMENT FILE NAME WAS FIXED.

Table of Contents

Description top

Even if the name may be confusing, this is a very simple and easy-to-use plugin. The aim is to be the ultimate solution for changing models/sprites/sounds.

It provide two ways of replacing:
  • Complete replacement
    • Pros
      • Work in all HL mods.
      • Using better methods to accomplish the same results. The memory is patched at map start, just one time. This brings some drawbacks, you can read them below.
      • All-In-One, you can change sprites,sound and models. It's not only for weapons.
      • Easy to configure.
      • The old resources are not precached, so it won't increase the precache list, it won't over 512 :D
    • Cons
      • The string that will replace another one must have a size lower or equal than the original one. Not a big deal, just rename it if it's too long.
      • You can't change things per player, you can't have resources for vips and another resources for normal players or stuff like that. Everything is global.
  • DynamicReplacement
    • Pros
      • Allow you to change dynamically player models, weapon models & sounds]
      • You can change them only for a player, only for a team, for admins or for all.
      • You can also replace a specific model with another one.
      • As you can see, all the cons from the complete replacement become pros here. By combining this two ways I'm sure you won't need another replacement plugin.
    • Cons
      • It will increase the precache limit

Please read the full post, if you want to be able to run this plugin properly and to take advantage of all features that it's providing.

From version 1.3 a version checker was included. This mean that the plugin will connect to http://hamletplugins.comyr.com/test.html to get the lastest version and inform you if you are running the latest one or you should update. It also gets the changelog for the next version. If you are running an older one the plugin will automatically print the changelog for latest version so you know what changes were done.

Example:
Code:

L 06/28/2015 - 10:21:10: [test2.amxx] Your version 1.2 is outdated. Last version is: 1.3
L 06/28/2015 - 10:21:10: [test2.amxx] Changelog for V 1.3:
L 06/28/2015 - 10:21:10: [test2.amxx] + Added version checker
L 06/28/2015 - 10:21:10: [test2.amxx] + Better filtering for wrong configurations, missing models/sounds
L 06/28/2015 - 10:21:10: [test2.amxx] + Added changelog display for suggested version
L 06/28/2015 - 10:21:10: [test2.amxx] + Filtering mp3 files to prevent user input errors
L 06/28/2015 - 10:21:10: [test2.amxx] + Added a new identifier for replacement - admin flags
L 06/28/2015 - 10:21:10: [test2.amxx] + Flags are now additive for player & weapon models
L 06/28/2015 - 10:21:10: [test2.amxx] + Code cleaned
L 06/28/2015 - 10:21:10: [test2.amxx] + Fixed some tipos

Requirements top

This doesn't require much special things, only:
  • Orpheu module.
  • A server without dproto.
    This is not generally needed, but I won't help you if you are running an outdated server with dproto. If you are experiencing problems, update your server/ fix the erros by yourself.
Installation top[INDENT]
To install the plugin:
  1. Download the resources from this post. You need to get the source and compile it locally.
  2. Put entities_resources_replacement.amxx in addons/amxmodx/plugins
  3. Put entities_resources_dyn_replace.ini in addons/amxmodx/configs
  4. Put entities_resources_comp_replace.ini in addons/amxmodx/configs
  5. Open addons/amxmodx/configs/plugins.ini and add at the end of this file entities_resources_replacement.amxx
  6. You can put the sma file into addons/amxmodx/sources but this is not mandatory.
  7. Copy the content from orpheu folder to addons/amxmodx/configs/orpheu
  8. Restart the server/change map.

To install orpheu:
  1. Download orpheu_files-2.5.1.zip and extrat the arhive.
  2. Copy orpheu_amxx.dll/orpheu_amxx_i386.so depending on your operation system into addons/amxmodx/modules
  3. The module will be auto-loaded, you don't need to add it into modules.ini

To compile locally:
  • First way:
    1. Download AMX Mod X for windows/linux from main site
    2. Extract somewhere the arhive and remember the folder!
    3. Copy the content from include folder from the orpheu arhive into addons/amxmodx/scripting/include( in the folder created in the step 2 ).
    4. Download celltravtrie.inc that is attached to this post and put it inside include. The one from Hawk post seems to be changed and is missing a stock.
    5. Download the source of the plugin( entities_resources_replacement.sma) from this post and drag it over the compile.exe(scripting folder from the arhive created at step 2)
    6. It will create a new folder called compiled. Open it and you will find your compiled plugin( entities_resources_replacement.amxx )
  • Second way:
    1. Go to http://spider.limetech.org/
    2. Copy/paste the code from the .sma file into the website.
    3. Under the big blue Compile button you see a box which Drop .inc files here
    4. Then press Compile and Download

Configuration top


You can use complete replacement file, dynamic replacement or both at the same time! In order to switch from one to other you need to change the cvar ToggleReplacementType.
Change this value to 1 for complete replacement, to 2 for dynamic replacement or to 3 for both replacements. Note that this cvar in cached, so new values are read after map change.

To configure complete replacement file:

Open entities_resources_comp_replace.ini and you will see some instructions on how you should use the plugin.
You need to know that you can change resources in all maps, or they can be map specific. In order to acquire this:
  • Map specific: rename the file, including the map name: entities_resources_comp_replace.ini -> entities_resources_comp_replace-map_name.ini. If you want the resources to be change only in de_dust2 you would do entities_resources_comp_replace-de_dust2.ini. It's very important to write the map name correctly!
  • Global changes: just let the name as entities_resources_comp_replace.ini. There is no problem if you have a global config and some configs that are map specific. If the needed map is running it will load the map config, otherwise it will load the default one.
  • No configuration file: if no configuration file is found, the plugin will be paused in the current map.

To change resources one would do
Code:

new_resource old_resource
You can replace sprites, sound and models. A path should look like
Code:

models/sound/sprites/file_name.mdl/wav/spr
For sounds, you still need to write sound/ in path, it will be automatically removed inside the plugin.

Some examples:
  • To change models:
    Code:

    models/v_ak47.mdl models/v_m4a1.mdl
    models/p_ak47.mdl models/p_m4a1.mdl
    models/w_ak47.mdl models/w_m4a1.mdl

    This will change all the ak47 models to m4a1 models. Silly, but it's a clear example.
  • To change sounds:
    Code:

    sound/weapons/knife_hitwall1.wav sound/weapons/ak7-1.wav
    This will change knife_hitwall1.wav sound to ak47-1.wav sound. You are not allowed to use mp3 files, PLEASE only .wav sounds.
  • To change sprites:
    Code:

    sprites/old.spr sprites/new.spr
    You will do the same as for sounds and models, too lazy to write an example. This feature is very good, as you no longer need plugins as "he explosion sprite changer" and so.

To configure dynamic replacement file:

Open entites_resources_dyn_replace.ini and you'll have full instruction with examples.

You need to know that you can change resources in all maps, or they can be map specific. In order to acquire this:
  • Map specific: rename the file, including the map name: entites_resources_dyn_replace.ini -> entites_resources_dyn_replace-map_name.ini. If you want the resources to be change only in de_dust2 you would do entites_resources_dyn_replace-de_dust2.ini. It's very important to write the map name correctly!
  • Global changes: just let the name as entites_resources_dyn_replace.ini. There is no problem if you have a global config and some configs that are map specific. If the needed map is running it will load the map config, otherwise it will load the default one.
  • No configuration file: if no configuration file is found, the plugin will be paused in the current map.

As from version 1.3, some interesting things were added:
  • For both weapons & player models new type of replacement was added, by admin flags. You must write Flag_letters. If you want to give a model to all admins that have ban acces you must do Flag_d and the rest is the same, write the model as for any other replacement type(team/steam etc)
    • Example:
      Code:

      Flag_d models/v_ak47.mdl models/v_m4a1.mdl models/p_m4a1.mdl models/w_m4a1.mdl
      Flag_abcdefghijklmnopqrstu models/v_m4a1.mdl models/v_ak47.mdl models/p_ak47.mdl models/w_ak47.mdl

    • A new cvar was added: AdminFlagsReadType -> change the way in which admins flags are checked.
      • 0 means contain - the flags from file must be contained in user flags.
      • 1 means equal - flags from file must be the same as the user flags.
      • Example: in the file we have the flags abc and a user with flags abcdefghijklmnopqrstu
      • If the cvar value is 0, he will get the model, because abc is contained in abcdefghijklmnopqrstu
      • If the cvar value is 1, he won't getthe model, because abc is not equal to abcdefghijklmnopqrstu
  • The biggest and most interesting part, flags are now additive, this mean you can combine them with "+".
    • Example:
      Code:

      STEAM+TEAM_CT some_model
      STEAM+TEAM_TERRORIST some_other_model
      Flag_abcd+TEAM_CT+STEAM_ some_model


You are not limited at only two flags, you can combine as many as you want, but without ALL flag. Also, the same thing can be done for weapon models.
  • Change Weapon Models
    • Go to [WEAPON MODELS]
    • Read the instructions from file, I'm not going to repost here
    • Under ;Add your models below: add your new resources
    • Example: ALL models/v_ak47.mdl models/v_m4a1.mdl models/p_m4a1.mdl NULL
    • Use NULL in order to skip a model from the syntax.
    • Syntax:
      • STEAM_...... v_old_model v_new_model p_new_model w_new_model
      • Flag_acces v_old_model v_new_model p_new_model w_new_model
      • TEAM_TERRORIST model v_old_model v_new_model p_new_model w_new_model
      • TEAM_CT model v_old_model v_new_model p_new_model w_new_model
      • ALL model v_old_model v_new_model p_new_model w_new_model
  • Change Player Models
    • Go to [PLAYER MODELS]
    • You have full instructions, please pay attention on them.
    • Under ;Add your models below: add your custom models
    • Example: TEAM_CT antifurien
    • Use NULL in order to skip a model from the syntax.
    • Syntax:
      • STEAM_...... model
      • Flag model
      • TEAM_TERRORIST model
      • TEAM_CT model
      • ALL model
      • OldModel modell
  • Change Sounds
    • Find [SOUND SECTION]
    • Again, read the instructions from the file.
    • Under ;Add your sounds below: add your custom sounds
    • Syntax: old_sound new_sound
  • Change sprites
    • Find [SPRITE SECTION]
    • Again, read the instructions from the file.
    • Under ;Add your sprites below: add your custom sprites
    • Syntax: old_sprite new_sprite

Important:If you see that some of your resources are not replaced check server console & logs file, when some files are skipped, you will find there the full reason.

API top

What mean API ? API stands from Application Programming Interface and it's here for compatibility purpose.

INC file:
PHP Code:

#if defined _err_api_included
    #endinput
#endif
#define _err_api_included

/**
    *  This native is for compatibility purpose.
    *  You search for a default string and it will point you to the new one.
    *  Example: →  models/v_ak47.mdl(old string) models/v_m4a1.mdl(new string)
                → By searching for models/v_ak47.mdl you will get models/v_m4a1.mdl
    *
    *  @param Input            The string that you want to search for.
    *  @param Output           The buffer in which the found string will be saved.  
    *  @return                 -1 on failure, 1 otherwise
*/
native err_find_replaced_string(const Input[], const Output[])

/**
    *  Return replacement type
    *  Check replacement type before using err_find_replaced_string

    *  @return    →  -1 on failure. 
                →  1 for complete replace 
                →  2 for dynamic replace 
                →  3 for both
*/
native err_find_replace_type() 

As you can see it has two natives. The inc file is self explanatory, just read the documentation.

Plugin Example
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <err_api> //include the custom library

public plugin_init() 
{
    if(
err_find_replace_type() != 2)
    {
        new 
szString[128//this will be the buffer in which the output will be stored.
        
err_find_replaced_string("models/v_ak47.mdl"szString//find what replaced models/v_ak47.mdl string
        
server_print("Searched models/v_ak47.mdl | Found:%s"szString//print it to server console.
    
}


err_find_replaced_string native will return -1 on failure, it's up to you to check this before working with the output.
The native is usefull when you want to run other plugins that do stuffs in FM_SetModel and check for default model name. To be sure you check the right model, search with this native for the original one, if it was replaced it will point you to the other one.
Credits top
  • Arkshine: some ideeas
  • BackStabNoob: topic design
ChangeLog top
  • V 0.1:
    • Initial release
  • V 0.2:
    • Added support for sounds.
    • Removed an useless cvar.
    • Minor improvements.
  • V 0.3:
    • Fixed some stuffs.
    • Added more checks to prevent user errors.
  • V 0.4:
    • Added support for sprites.
    • Added more and more checks to prevent user errors.
  • V 0.5:
    • Removed some useless checks, plugin will be paused in that situations
    • Fixed another silly mistake
  • V 0.6:
    • Remove some useless arrays
    • Added a native for campatibility purpose
    • Code optimized, less checks.
  • V 0.7:
    • Added DefaultDeploy() hook
    • Using orpheu to hook DefaultDeploy(), some troubles with okapi
    • Added dynamic replacement way
    • Added support for dynamic changind player models, sounds and weapon models
    • Changed a bit my code style
    • Added more checks to prevent user errors
    • Fixed the encoding bug with complete replacement file
  • V 1.0:
    • Fixed some bugs.
    • Now you can use both replacement types at the same time.
  • V 1.1:
    • Fixed bugs with model setup
    • Added new option: replace a model with another one
    • Code optimized
  • V 1.2:
    • Fixed identation
    • Code cleaned a bit.
    • Removed something left here by mistake after testing.
  • V 1.3:
    • Added version checker
    • Better filtering for wrong configurations, missing models/sounds | Added changelog display for suggested version
    • Filtering mp3 files to prevent user input errors
    • Added a new identifier for replacement - admin flags
    • Flags are now additive for player & weapon models
    • Code cleaned
    • Fixed some tipos
  • V 1.4:
    • Fixed DefaultDeploy() signature, it should be more reliable now.
    • Fixed a crash with unpatching memory in certain situations.
    • Fixed a crash that happened when plugin was paused.
    • Fixed a typo in dynamic replacement file name.
    • Fixed a bug that occured while trying to get the changelog. Plugin was priting error messages when it was not the case.
    • Code was completely rewritten, now it's easier to maintain and understand. Also it makes more sense now.
    • Added sprite replacement in dynamic replacement mode.
    • Proper checks are enforced on resources.
    • Configuration files were rewritten, instructions are much more clear, for the sake of usability.
    • Probably much more things that I can't remember.
Downloads top
  • V 0.1: 23 downloads
  • V 0.2+0.3: 20 downloads
  • V 0.6: 45 downloads
  • V 1.0: 128 downloads
  • V 1.2: 64 downloads
  • V 1.3: 242 downloads

Jhob94 10-20-2014 15:39

Re: Weapons Model Replacement[ OKAPI ]
 
Seems nice but i think you should explain why we should use this instead of Chronic's one.

HamletEagle 10-20-2014 15:46

Re: Weapons Model Replacement[ OKAPI ]
 
Quote:

Originally Posted by Jhob94 (Post 2213651)
Seems nice but i think you should explain why we should use this instead of Chronic's one.

His old one is very inneficient speacking about coding methods:
1. He is using currentweapon for changing weapons models.
2. He is using format and not formatex.
3. So on...
4. Mine use okapi which patch the string directly into memory, just one time.

yokomo 10-20-2014 16:37

Re: Weapons Model Replacement[ OKAPI ]
 
Have you try to change string longer than original?
Example: models/v_ak47.mdl --> models/v_ak47_the_one_and_only.mdl

Because in Orpheu we can't patching string > original string.

** Edited **
Nevermind
Quote:

By default, you can put a path with the same size as the original one or lower. Safe mode allows you to disable this restriction. If you don't want to be limited, set it to 1, but I would recommend to keep it with 0 and modify the new model name to be shorter than the original one.

Jhob94 10-20-2014 17:42

Re: Weapons Model Replacement[ OKAPI ]
 
I don't like to test plugins in my oficial servers and i am lazy to read the code so is better to ask. If i run an external plugin for give some people private weapon skins wich are set at item deploy, would that external plugin work?
And since i am talking about this, i think it would be a nice idea to allow setting skins by user flags and also steam id (Steam ID would override flags). Would be more original and make a easy job for many people :)

Could be:
.Normal Replace - "models/v_knife.mdl" "models/hamlet_server/v_knife.mdl"
.Flags Replace (Example, ADMIN_BAN) - "models/v_knife.mdl" "models/admins/v_knife.mdl" "d"
.Steam ID Replace - "models/v_knife.mdl" "models/jhob/v_knife.mdl" "STEAM_0:1:39788919"

Arkshine 10-21-2014 04:29

Re: Weapons Model Replacement[ OKAPI ]
 
I don't see the point of wmr_safemode_off cvar ; as it should fuck up memory if you use a new string size > original size one (like you example..)

Quote:

Not needed, but let's make sure.
Pointless, please don't make unnecessary steps. Auto-loading is working fine, don't start to make people mixing both.

Jhob94 10-21-2014 05:39

Re: Weapons Model Replacement[ OKAPI ]
 
I believe you can use other stuff to save strings into memory, even if not only one time, there is stuff that require such few cpu consume that people won't really care. But using an external module just for this thing seems useless and many people might dont want to use it. Example, i know one owner of a big community that has the server really high ranked. He owns it for like 5 years and few weeks ago i was helping him fixing chat crashes and when i sent the sma he didnt knew what it was because there are many people who just comes and download amxx.
Since you using that module just for a few memory settings, i think its a bit useless. But at the end its your choice.

HamletEagle 10-21-2014 09:01

Re: Weapons Model Replacement[ OKAPI ]
 
Quote:

Originally Posted by Jhob94 (Post 2213697)
I don't like to test plugins in my oficial servers and i am lazy to read the code so is better to ask. If i run an external plugin for give some people private weapon skins wich are set at item deploy, would that external plugin work?
And since i am talking about this, i think it would be a nice idea to allow setting skins by user flags and also steam id (Steam ID would override flags). Would be more original and make a easy job for many people :)

Could be:
.Normal Replace - "models/v_knife.mdl" "models/hamlet_server/v_knife.mdl"
.Flags Replace (Example, ADMIN_BAN) - "models/v_knife.mdl" "models/admins/v_knife.mdl" "d"
.Steam ID Replace - "models/v_knife.mdl" "models/jhob/v_knife.mdl" "STEAM_0:1:39788919"

Your suggestion is impossible to be done with okapi, it's patch the string directly into memory one time, in plugin_precache and at this point there are no players connected + the original string is replaced by new one, the model is not simply "changed" as happen when using pev_viewmodel12 and so.

Quote:

Originally Posted by Arkshine (Post 2213865)
I don't see the point of wmr_safemode_off cvar ; as it should fuck up memory if you use a new string size > original size one (like you example..)


Pointless, please don't make unnecessary steps. Auto-loading is working fine, don't start to make people mixing both.

As you say...

Quote:

Originally Posted by Jhob94 (Post 2213890)
I believe you can use other stuff to save strings into memory, even if not only one time, there is stuff that require such few cpu consume that people won't really care. But using an external module just for this thing seems useless and many people might dont want to use it. Example, i know one owner of a big community that has the server really high ranked. He owns it for like 5 years and few weeks ago i was helping him fixing chat crashes and when i sent the sma he didnt knew what it was because there are many people who just comes and download amxx.
Since you using that module just for a few memory settings, i think its a bit useless. But at the end its your choice.

"I believe you can use other stuff to save strings into memory,"
No, only possible with okapi/orpheu which acts in the same way. The point of this plugin is to use the best way, it's not my problem if some owners can't read the instructions or if they are not able to use it.

Arkshine 10-21-2014 09:19

Re: Weapons Model Replacement[ OKAPI ]
 
Quote:

As you say...
I don't understand why you answer that.

HamletEagle 10-21-2014 10:30

Re: Weapons Model Replacement[ OKAPI ]
 
Because I don't like to write much text when it's not needed. For auto-loading, in the past I experienced some problems, this is why I'm writing this in the install instructions but if you say that now it's working fine it's ok.
About safe mode cvar, I know it's a bit useless and unexperienced owners may screw up memory, I don't know what was in my mind when I've added this.

UPDATE:

V 0.2:
+ Added support for sounds
+ Removed the cvar.

Jhob94 10-21-2014 10:49

Re: Weapons Model Replacement[ OKAPI ]
 
Well, when you have your definitive final version, you should request an approver/moderator to add everything to zip file including amxx for make the job easier to who doesn't knows how to compile localy.
And nice that you added sounds support :)

HamletEagle 10-21-2014 10:52

Re: Weapons Model Replacement[ OKAPI ]
 
Quote:

Originally Posted by Jhob94 (Post 2213988)
Well, when you have your definitive final version, you should request an approver/moderator to add everything to zip file including amxx for make the job easier to who doesn't knows how to compile localy.
And nice that you added sounds support :)

Thx for your advice, I will do it.

Arkshine 10-21-2014 13:03

Re: Weapons Model Replacement[ OKAPI ]
 
I don't have much to say for now, but I think you should review your "Usage" section. It's confusing and kind of unreadable.

Like for example:
- you say in 1. to create a file, but you provide already a config file.
- The config file should contain a dummy example with explanations.
- Make sure to warn about not using mp3 sounds.
- Make sure to emphasis about the length restriction.
- Make sure to emphasis about putting the map name.
- Your example should follow your current config file syntax, and you should not hesitate to use [code] bbcode.
- No need to duplicate 2 times your examples
- Basically rewrite the whole section \o/.

HamletEagle 10-21-2014 13:15

Re: Weapons Model Replacement[ OKAPI ]
 
Ok, this is for the topic, about the code do you spot some problems ? Yeah, I will rewrite it.

Edit: done, new file uploaded.

Arkshine 10-21-2014 13:50

Re: Weapons Model Replacement[ OKAPI ]
 
Code as it is seems ok.

Though you can always improve a bit:
  • If g_arraySize is empty, you could already destroy the Array and not calling patchMemory.
  • Put some comment about what does the plugin and cvar. Best practice would be an admin doesn't need to check the first post of the plugin thread to know how about what plugin does/how to config/how to insall etc.
  • I think you should check the string size in plugin and warn about it (meaning ignoring it in case new size > original one + log_amx for example).
  • Increase buffer for get_configsdir ; remember that's something that any admin could change in core.ini. 32 might a bit short.
  • I'm not sure to like how you parse the section in your config file. For safety, you should explicitly check for section name. Even better, you don't need section at all, there is no reason to separate like that, you can always do that with comments and in your code, just a matter to check extension for example. Less prone to user's error.

HamletEagle 10-21-2014 14:07

Re: Weapons Model Replacement[ OKAPI ]
 
I like too much my parsing method and if a user simply fallow the instructions he can't be wrong :D
Everything else updated.

Arkshine 10-21-2014 15:20

Re: Weapons Model Replacement[ OKAPI ]
 
But I don't care you like much your method. :twisted:
You should also be aware that you can be sure user won't follow instructions. Never trust user. A gold rule. This is not a joke.

When you think again, more things:
  • You must check if file exists before and warn about it if not (optional but welcomed). This means you will have to deal with "sound/" because you need the full path with file_exists, and best would be probably to force user to prepend sound/, then in the code just a matter to do string[6] to ignore it. You can do the reverse too.
  • Actually you don't need to precache. Since you're using a way to replace directly in memory, this means, file will be precached properly by the game. No need to duplicate this. At the end, this makes your section totally pointless since you're using that only for precache. That's simplify your code.

Since I'm a evil bastard, the last point should make you realize your plugin is no more about only Weapon Model anymore but a generic memory replacer for entity's resources. That's it, your plugin can replace any sounds/models/sprites that the game precaches. You should rename your plugin to something else. Don't tell me you want to keep only for weapons, it would not make sense at all since your plugin would already allows that \o/, and it's better to be generic so your plugin has more chance to be used for more things.

If you are a masochist, you could take the thing a bit further, like config file allows to replace any string (so not a file, your have already the code ready).
If you are a masochist, you could add some parameter in config file to replace any string in the engine library as well.

HamletEagle 10-22-2014 11:14

Re: Weapons Model Replacement[ OKAPI ]
 
Quote:

Originally Posted by Arkshine (Post 2214125)
But I don't care you like much your method. :twisted:
You should also be aware that you can be sure user won't follow instructions. Never trust user. A gold rule. This is not a joke.

When you think again, more things:
  • You must check if file exists before and warn about it if not (optional but welcomed). This means you will have to deal with "sound/" because you need the full path with file_exists, and best would be probably to force user to prepend sound/, then in the code just a matter to do string[6] to ignore it. You can do the reverse too.
  • Actually you don't need to precache. Since you're using a way to replace directly in memory, this means, file will be precached properly by the game. No need to duplicate this. At the end, this makes your section totally pointless since you're using that only for precache. That's simplify your code.

Since I'm a evil bastard, the last point should make you realize your plugin is no more about only Weapon Model anymore but a generic memory replacer for entity's resources. That's it, your plugin can replace any sounds/models/sprites that the game precaches. You should rename your plugin to something else. Don't tell me you want to keep only for weapons, it would not make sense at all since your plugin would already allows that \o/, and it's better to be generic so your plugin has more chance to be used for more things.

If you are a masochist, you could take the thing a bit further, like config file allows to replace any string (so not a file, your have already the code ready).
If you are a masochist, you could add some parameter in config file to replace any string in the engine library as well.

Now it has suport for sprites, sounds and weapons :D

Arkshine 10-22-2014 11:33

Re: Weapons Resources Replacement[ OKAPI ]
 
You did not rename your plugin. What plugin does is not related to weapon specifically anymore, but to entities more generally. An entity can be a weapon, an item, or anything else like func_*, env_* etc. Such entities precaches resources as well (just look at HLSDK.

HamletEagle 10-22-2014 11:51

Re: Weapons Resources Replacement[ OKAPI ]
 
Quote:

Originally Posted by Arkshine (Post 2214472)
You did not rename your plugin. What plugin does is not related to weapon specifically anymore, but to entities more generally. An entity can be a weapon, an item, or anything else like func_*, env_* etc. Such entities precaches resources as well (just look at HLSDK.

You forgot to close ) :twisted:
Check the code, forget the name, it can be easely changed :P I'm sure you still have a lot of suggestions.

Jhob94 10-22-2014 13:09

Re: Entity Resources Replacement[ OKAPI ]
 
nice, really nice. Btw you could tell us wich sprites it can replace. For example i heard that radar sprite is impossible to replace so you should make a list. But very nice, i start liking and considering to use this plugin :)

HamletEagle 10-22-2014 13:50

Re: Entity Resources Replacement[ OKAPI ]
 
Attachement removed, just spotted some dumb mistakes into the source, I will upload it when they are fixed.

Edit: fixed.

Arkshine 10-22-2014 13:58

Re: Weapons Resources Replacement[ OKAPI ]
 
Quote:

Originally Posted by HamletEagle (Post 2214475)
I'm sure you still have a lot of suggestions.

Of course, like:
  • You did not care to test properly your code before releasing it. Like the first okapi_mod_replace_string which is out of loop... :nono: (EDIT: looking at your previous post, you probably fixed that)
  • You use 2 copy... but why not using directly arrayData in parse?
  • I'm not sure why you check for .mdl / .spr ; this doesn't seem useful.
  • Well, about sound/, I told you have 2 ways, but honestly this makes more sense and is more consistent that user has to add sound/ in config file, like he has to add models/ and /sprites. This also simplify your code.
  • You should rewrite your description in first post. This is kind of incomplete, not really clear, with some pointless sentences. You should also clearly list the pros and cons of your plugin (for example pros: you have probably work for all mods, the most efficient method, can replace any entity resources ; and cons: probably the limit about length which could be a pain, global (can't be done per-player, etc.), possible incompatibility with plugins which check the original model name, etc.). This is important to an admin to understand at first glance whether this plugin is suitable for their needs. So please take time to properly elaborate your plugin description.

HamletEagle 10-22-2014 14:34

Re: Entity Resources Replacement[ OKAPI ]
 
Done. I've added a second array with only the string that were replaced for unpathMemory function, to avoid making the same checks as in pathMemory. The topic will be rewrited tomorow.

ANTICHRISTUS 10-22-2014 15:32

Re: Entity Resources Replacement[ OKAPI ]
 
you edited your plugin's name ? so basically it's no longer a replacement of the Weapon Model Replacement but a replacement of the Content Replacer one. right ?

my advice is to make separate plugins, and to use easy topic names (to search for/remember them easily).

HamletEagle 10-22-2014 15:39

Re: Entity Resources Replacement[ OKAPI ]
 
Quote:

Originally Posted by ANTICHRISTUS (Post 2214561)
you edited your plugin's name ? so basically it's no longer a replacement of the Weapon Model Replacement but a replacement of the Content Replacer one. right ?

my advice is to make separate plugins, and to use easy topic names (to search for/remember them easily).

It's a replacement for both of them :D There is no point in having different plugins, this one can to the same job :D

yokomo 10-23-2014 01:58

Re: Entity Resources Replacement[ OKAPI ]
 
Actually just put "String Replacement" in your thread tittle, it just change string.

This replacement is for global. The plugin from GHW is better because you can replace string > original. I believe every community has it own sound/models/sprites folder, and of course they want use their own path (sound/picollo/mysound.wav). Your plugin is limited and i don't think this is useful. You can do with Opheu too, see http://forums.alliedmods.net/showthread.php?t=117930

Very simple right.

HamletEagle 10-23-2014 09:23

Re: Entity Resources Replacement[ OKAPI ]
 
Quote:

Originally Posted by yokomo (Post 2214690)
Actually just put "String Replacement" in your thread tittle, it just change string.

This replacement is for global. The plugin from GHW is better because you can replace string > original. I believe every community has it own sound/models/sprites folder, and of course they want use their own path (sound/picollo/mysound.wav). Your plugin is limited and i don't think this is useful. You can do with Opheu too, see http://forums.alliedmods.net/showthread.php?t=117930

Very simple right.

Some users may not know what a string is, the current name is just fine. How could you say what GHW's is better ? Speacking about restrictions, yes, his one doesn't has many restriction, but considering his code it's very inneficient, using old file natives, using currentweapon and so on. I know it can be done with orpheu, but why creating a signature when with okapi I need just one line ? If the sound has not a plugin that's using it you can short it's name, this is no problem, and if it has already one what's the point in using my plugin ? So, this is not a problem. Of course, you can consider it's useless, but this won't stop me from updating this. :D

Arkshine 10-23-2014 10:26

Re: Entity Resources Replacement[ OKAPI ]
 
Same for you, is there a specific reason you're ranting and raving about this?
But I agree that this plugin should not be considerated as a total replacement of existing plugins.
Both plugins have its pros and cons. That's why description should be more clear about it. It's fine to have both way.

HamletEagle 10-23-2014 13:25

Re: Entity Resources Replacement[ OKAPI ]
 
Updated to 0.5, this brings some code improvements and some mistakes fixed.

Arkshine 10-23-2014 18:21

Re: Entity Resources Replacement[ OKAPI ]
 
Your first post is better. But you should improve more because you don't explain properly all and this could be confuse some people.

There is something you should keep in mind: your plugin is an alternative to some plugins. Because of your plugin can't replace all features of others plugins, you can't consider this one a full replacement. This could be the case depending the admin's needs, but by default, no.

Next, your description doesn't tell really what the plugin offers, in the meaning, why should I use this plugin.
Your comparison section is welcomed, but I think that's something which should written below the plugin description (included, I mean) as it matters to know right away what plugin can do and what it can't do.
Also, your last sentences from "Sure that..." are sincelery pointless, as this doesn't help to understand.

I won't tell you how to write it, but in my opinion, this could be similar to something like (just main idea):
Quote:

This plugin is meant to be an alternative to plugins X and Y. The purpose is to globally replace any entity's resources server-side. An entity can be a weapon, an item, or anything map-related.
Because of the method used to replace the original resource is straightforward, this offers several advantages but also few drawbacks.

Advantages:
  • This can replace any kind of resources (sprites, models, sounds and events)
  • The most efficient and reliable method of replacement (memory patch applied one time at map start).
  • Only the new resource is precached (no duplicate with the original string).
  • This plugin works on all HL1 mods.

Drawbacks:
  • The new resource must have its string length inferior or equal to the original one. Just matter to rename if needed.
  • You can't change things per player/team, you can't have resources for vips and another resources for normal players or stuff like that. Everything is global.
  • Using it may produce some troubles with other plugins that check original model name to change stuffs (like model check in FM_SetModel).

You get the idea.

Some notes:
  • To compile manually, you can still give steps using http://spider.limetech.org/ ; it can accept user uploading his own includes.
  • Don't forget you can ask any Approver/Moderator to compile plugin for you, then you can attach it.
  • You should probably say this can't replace client sound.
  • Maybe you should say some words about checking amxx log in case of issues, as pluyin throw some messages.
  • Well, if you are masochist, this should be very welcomed you provide a reference list of all resources server-side which can be replaced. This should not that hard to generate, and just a matter maybe to add some comments so we know to what entity is associated. This could be really handy when you have no idea what resources are used for something and will avoid questions. Well, just give some thoughts.

--

About code:
  • #define ADMIN_ACCES ADMIN_RCON ; is it supposed to do something?
  • In patchMemory, the else { } is pointless.
  • In patchMemory, you should not use formatex when source and destination are the same.
  • In patchMemory, you could just use ArrayDeleteItem, there is really no reason to create a new array and push each time. An ignored resource shoulf happen less often. Don't forget to decrease g_arrayReplacedSize.
  • Don't forget to update comments at the top

About improving plugin, if you want this to become really a remplacement among all existing plugins, then you should also hook forwards. Since you're using Okapi, you could for example for weapons hooking directly DefaultDeploy(), etc. You could create a more advanced configuration and depending what want the admin you choose between memory patch or hooking forwareds. Well, just give some thoughts.

yokomo 10-23-2014 19:59

Re: Entity Resources Replacement[ OKAPI ]
 
Haha, like i said this is not useful at all, better to make it as tutorial. Sorry to say that.

Arkshine 10-24-2014 03:22

Re: Entity Resources Replacement[ OKAPI ]
 
How it's not useful. Elaborate?

yokomo 10-24-2014 05:41

Re: Entity Resources Replacement[ OKAPI ]
 
Quote:

Originally Posted by Arkshine (Post 2215105)
How it's not useful. Elaborate?

This such plugin already exist, GHW is outdated but it still stable to use. Like i said in previous post, certain community has it own custom path example "models/awesome/v_ak47_new.mdl" that was long. Also if we patch string using okapi how about other plugin that hook FM_SetModel?

Like ZP it hook FM_SetModel to detect grenade throw, if our path has been patched what will happen to the ZP plugin?

Arkshine 10-24-2014 05:51

Re: Entity Resources Replacement[ OKAPI ]
 
Does GHW plugin unprecaches old resources? No. Just that, plugins makes sense.
Own custom path? Just rename it. This is sincerely not a valid argument.
how about other plugin that hook FM_SetModel? That's the whole point this plugin is not replacement but an alternative. You could want to build a very efficient mod around this for example. It would be a good idea this plugin stores somewhere the old resource string, and others could check this, this could improve a bit compatibility. This is the most annoying side-effect, but not that a big deal. Also, this you're using this plugin, this doesn't make sense anyway to use others plugins which change same resources.

Like it has been said, both have pros and cons. It's all depending the needs. Nothing wrong with that. On the contrary, you have more choice to how build your configuration. No need to bash this plugin because you don't have any use with it.

yokomo 10-24-2014 06:18

Re: Entity Resources Replacement[ OKAPI ]
 
Quote:

Also, this you're using this plugin, this doesn't make sense anyway to use others plugins which change same resources.
I said if someone use both. This plugin change w_hegrenade.mdl for global.
But ZP change w_hegrenade.mdl for 2 models (1 for human and 1 for zombie).

Whatever, but yes it's good to replace a string for global.

K Bye.

Eating kebab.

Arkshine 10-24-2014 06:41

Re: Entity Resources Replacement[ OKAPI ]
 
But there is no reason to use both at the same time. You have also a config per map, and you can also not replacing with this plugin the w_ model if you have another plugin changes it. At the end, just a matter to understand what does the plugin and to configure properly. That's why I want the first post be clear about this.

HamletEagle 10-24-2014 11:44

Re: Entity Resources Replacement[ OKAPI ]
 
Post updated, also updated the plugin.

+Remove some useless arrays
+Added a native for campatibility purpose
+Code optimized, less checks.

@yokomo, I understood your "problem", if you don't find this useful is fine, just avoid the theard. But I can't get why you say that, you are not limited only at weapons and the biggest problem with FM_SetModel had been solved by adding a native that will point you to the replaced string :D

Kia 10-26-2014 10:30

Re: Entity Resources Replacement[ OKAPI ]
 
Plugin looks sexy, although I probably will not need it. :)
But I am sure I will link this to others when they need to replace stuff.

HamletEagle 10-26-2014 12:38

Re: Entity Resources Replacement[ OKAPI ]
 
Quote:

Originally Posted by Kia (Post 2215941)
Plugin looks sexy, although I probably will not need it. :)
But I am sure I will link this to others when they need to replace stuff.

Thx :D

Arkshine, I need your opinion here.
Let's say that someone replace the string abcd with the string ab. Now everything is fine, but in unpatchMemory it will try to replace ab with abcd, and abcd is longer than ab, so here the problem appear. Sure that I can request that the strings to have the same size, but I don't like to add one more restriction. What do you think ? I can ignore the okapi restriction here...


All times are GMT -4. The time now is 15:36.

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