Skin Changer Map Code

0 views
Skip to first unread message

Colette

unread,
Aug 4, 2024, 10:56:50 PM8/4/24
to kirsdanwordletz
Aspromised, here's the first in a series of follow-up posts on my initial 'introduction to Source hacking' post. This time we'll be adding the crucial missing feature from our skin changer: the ability to set custom knives.

Making a knife changer is surprisingly straightforward. Essentially, we just overwrite the item definition index of the default team knife with the custom knife of choice. Finally, we have to update the weapon model in our hands and then we're done.


First up, picking a knife to use. Personally, I'll be using my signature M9 Bayonet Crimson Web on the Terrorists side and my trusty Karambit Tiger Tooth on the Counter-Terrorists side. You can pick whichever you like but your mileage will vary with some of the newer knives such as the Butterfly Knife, Flip Knife and Shadow Daggers which have many unique animations that don't play nice with our changes. There's a workaround for local servers but that's a topic for another post.


Let's add two new cases to our switch statement. In them, we'll override the item definition index value to that of the replacement knife. If you're curious where these indexes came from, you can either take a look at the TF2B item listings or the raw items_game.txt file in the csgo/scripts/items folder.


There are a lot of entities in the Source Engine. Everything from physics props, weapons, buy zones, bomb sites, team spawnpoints and even your hands are all different entities with their own unique classes and variables. Just start up a local server and run report_entities in Console for a full list.


See the predicted_viewmodel entity? That's the model of our hands and weapon we see when playing or spectating someone else. To keep things simple, make sure you're in a server by yourself. Remove any bots from the game if needed with the bot_kick command. Next, enable cheats with sv_cheats 1 and finally, run cl_find_ent predicted_viewmodel in Console.


Now we know our view model entity is positioned at the 81st position in the entity list. There's a pretty cool command included in the Source Engine which can show you a load of information about an entity. Try it out by running cl_pdump followed by the index of your predicted_viewmodel entity in Console.


There's a lot to look at here but I'll draw your attention to the m_nModelIndex and m_hWeapon network variables. You'll notice as you switch between your guns and knife that these two will change. Let's take a quick look at some code from the Source Engine and see what they're doing to cause this change.


At the time of writing, I'm using this virtual function in the Windows version of my skin changer. Seems good enough, we can just find this function and call it. This function looks simple though, maybe we should look a little further.


May as well forget about calling the function, looks like writing the new model index over m_nModelIndex might be enough. However, we can't do that without our view model entity. We could iterate the entity list and compare m_hOwner against our local player but surely there's a better way. Perhaps our player entity can shed some light on this dilemma?


Oh nice, it was that easy. We'll just get the entity from the m_hViewModel handle. cl_pdump saves the day again. Looks like it's time to get these offsets. I know, this part sucks. I promise that the next post will be on dynamic NetVar scanning and then we'll never have to do this again.


Right. We're almost ready, there's still one more thing to do. In case you didn't notice, we have no idea what to set the model index to yet. Luckily, there is such a function to convert model filenames into indexes in the IVModelInfoClient interface!


Okay, this is actually the last thing left. We still don't know the filenames of the override knife models. There are a few ways to find this but it's probably easiest to search for occurences of model_player in the items_game.txt file. Alternatively, you could take a look in the models/weapons folder in pak01_dir.vpk but that's a bit more complicated.


I've cut out all the other weapons from the above output but if you really wanted to replace your knife with a gun.. well, nobody is stopping you. Anyway, we really do have everything now! Let's go back to our FrameStageNotify hook.


Now we'll check if this is a custom knife. If it matches the item definition index we set earlier then we'll overwrite the m_nModelIndex variable. I initially wanted to store the replacement model indexes in a static variable, but the indexes actually change between maps. There are still better ways of doing this, but this'll do the job for now.


Post note: After the 29 Nov 2016 update you must also set the model index on the active weapon. Failing to do this will leave you unable to apply paint kits to the replacement knife. An example implementation of this fix can be viewed here.


I am making a script in JavaScript that when a user types in a specific name then the script will load a skin. The issue is right now the code only works with 1 skin and I want it to work with multiple.


I got the base code of Github and I don't know too much about JavaScript. I am not the most smartest when it comes to it. I tried doing arrays by just making the to variables at the top to an array but that didn't seem to work.


The script actually works fine when I use it with 1 string of a name. I have used this script in Tampermonkey on Chrome and Violentmonkey on Opera. (Both running latest stable version.)


SkinChanger is a small plugin with fully customizable messages that allows you to change player skins to other players and display names using commands without requiring Spout or another custom client! You can also have a list of usernames in the configuration and when a player joins, the player will have a random skin out of the list of usernames (can have 1 player).


Please do not copy and paste this code and make it yours (even if you give me credit) and please do not post any of this code to BukkitDev (unless it's a util class such as Comphenix's PlayerDisplayModifier) without receiving my permission.


I am making a mod that allows the user to change there skin game, it far from complete, but bubbled it down to just setting a skin me and sister to test on my server for performance and we both ended up with are skin set on minecraft.net, but in my dev environment my skin does change to the one i set the set of code i am test is


To answer the question in your previous post, only use reflection when you can't use a normal method call/field access. Examples of this include accessing non-public methods/fields or methods/fields with a dynamic name/argument list and instantiating a class that's only known at runtime (i.e. you have a


I have subscribed to both PlayerLoggedInEvent and the EntityJoinWorldEvent, but i have a problem the EntityJoinWorldEvent is not trigger by a player and the PlayerLoggedInEvent gives me an EntityPlayer and not an abstract client player and i can not cast the EntityPlayer to an abstract client player


Wrong. EntityJoinWorldEvent is triggered by all entities joining the world, hence the name. Subscribe to the EntityJoinWorldEvent, check the instance of the AbstractClientPlayer against the event.entity, and then cast and do whatever you need. Remember, changing the skin with reflection during the EntityJoinWorldEvent will result in a NullPointerException (if you are changing NetworkPlayerInfo.locationSkin), so you will need to create a delayed runnable and schedule it to run on the main thread. Be sure to use ObfuscationReflectionHelper with SRG names.


This mod adds new commands to the 1.3 patch's fake console, which will allow you to change the appearance of units in-game (such as changing the legion of clone troopers). All four main factions will be supported.


Can I use this with ?

I originally thought it would be compatible with most mods, but I was wrong. After the release of the first beta I received dozens of crash reports. That said, it MAY still work with some mods, but all I can guarantee is that it'll work for the original, un-modded sides.


Will you release the assets?

When the mod is finished, i'll release the code for it. But not most of the skins, as they are made by others and can be found elsewhere. (Don't worry, they're all publicly released skins.)


I was originally hoping to finish the mod a long time ago, but as has happened with so many other modders, life got in the way, and the project was shelved. But now, after being reminded of it a lot recently, and with nothing better to do, I have finally returned, and this time, I'm not alone. Please welcome Needo62 to the development team!


But that's not all! I also have finally created an official Discord server for the mod. There you can chat with me and the other devs, give suggestions, and even get a chance at becoming an alpha tester!


I used to play with this mod a lot. Being able to change your skin even on vanilla maps was something pretty cool and you could play with this mod for thousands of hours, testing all the skins or even using them on custom maps that didn't include custom units. However the mod doesn't work correctly WITH Harrison BF2 Remaster (i suppose the issue is that, since the other 2 mods are required) and i think it's a bit disappointing. Most of the skins don't work and some crash. I'm not asking for a "collab" but a way to change the units even using his mod the moment you click over a skin.


Your comment action was successful. When a comment is deleted all replies to the comment will be removed as well. Because you are an admin, you can click the \"view deleted\" link above to view deleted comments in-case you wish to undelete them in the future. If this was a mistake, click the link again to reverse the change.

3a8082e126
Reply all
Reply to author
Forward
0 new messages