Wasteland 2: now with improved modding capabilities!

For community content (fan-art, fanfic, etcetera) for Wasteland 2.

Moderator: Ranger Team Alpha

Post Reply
karlito31
Initiate
Posts: 7
Joined: March 16th, 2019, 12:46 am

Re: Wasteland 2: now with improved modding capabilities!

Post by karlito31 » April 15th, 2019, 12:21 am

AliceInChains wrote:
April 14th, 2019, 9:28 am
Edit: I also tried to set Atlas and name directly to a .png file in the Sprite folder (without extension) but the icon still won't show up in Character skill tab (trying to add a new icon to a newly created skill: skill shows, but without icon)
I've had exactly the same problem. For a week I was smashing my head seeking a solution, but an icon for my Silent Move skill did not want to appear. In the end, I added my icon to the original WL2_Icons.png through the code. Every time I launch the game, my icon is added to WL2_Icons.png. Then you have to create a new object of "UISpriteData" type with the required coordinates, size and name of the new sprite and add it to the UIAtlas.spriteList. The name must correspond with the name assigned to the skill.spriteName ) Obviously, this requires a direct intervention in Assembly_CSharp.dll, but I did not find another way. Now everything works great. If you decide to use the Assembly approach, I can post the code later when I return home. In any case, if the executor_ has no solution to the problem through the modding interface, dnSpy is the best (and possibly the easiest) option.
Last edited by karlito31 on April 15th, 2019, 1:19 am, edited 1 time in total.

Executor_
Scholar
Posts: 207
Joined: August 11th, 2014, 5:38 am

Re: Wasteland 2: now with improved modding capabilities!

Post by Executor_ » April 15th, 2019, 12:46 am

The built-in icon files are only exported for reference purposes, they aren't designed to be modified. The patch notes for 0.9.2 explained how to add new icons:
  • can create new UIAtlas, the game's sprite databases
    • place picture files in a "Sprite" directory in "Import", valid extensions: PNG, JPG, JPEG
    • modded game will create a new UIAtlas from the image, with the UIAtlas having one item in the spriteList with the same name
    • refer to the picture as the filename without extension
    • eg. if you have testShotgun.png in your "Mods\Import\Sprite\" folder

      Code: Select all

      {
      	atlas : testShotgun
      	spriteName : testShotgun
      }
    • game probably resizes images automatically
    • don't forget about transparencies when creating pictures so that they look OK against the background

karlito31
Initiate
Posts: 7
Joined: March 16th, 2019, 12:46 am

Re: Wasteland 2: now with improved modding capabilities!

Post by karlito31 » April 15th, 2019, 1:03 am

Yes, but that doesn't work for skills, I think. I was creating new atlases in code from my "image.png" using all available functions (create, fromstring, my own variations, etc) and adding it to my skill, along with sprite name, same as atlas name, but icon never showed up. Only when I added it to WL2_Icons.png and placed new UISpriteData to iconAtlas instance, icon finaly showed up. I might be completely wrong here, obviously.

AliceInChains
Initiate
Posts: 3
Joined: April 14th, 2019, 2:50 am

Re: Wasteland 2: now with improved modding capabilities!

Post by AliceInChains » April 15th, 2019, 2:07 am

Executor_ wrote:
April 15th, 2019, 12:46 am
The built-in icon files are only exported for reference purposes, they aren't designed to be modified. The patch notes for 0.9.2 explained how to add new icons:
Doesn't work for Skill icons then. I did do exactly that after altering the WL2_Icons.png + .mson files had the icon not show up. It does work perfectly for changing icons of items in inventory/on character (black leather pants really are black leather now).
karlito31 wrote:
April 15th, 2019, 12:21 am
If you decide to use the Assembly approach, I can post the code later when I return home. In any case, if the executor_ has no solution to the problem through the modding interface, dnSpy is the best (and possibly the easiest) option.
If you could, that would be great.

karlito31
Initiate
Posts: 7
Joined: March 16th, 2019, 12:46 am

Re: Wasteland 2: now with improved modding capabilities!

Post by karlito31 » April 15th, 2019, 5:08 am

OK, here it is:
You will need dnSpy for this. Open Assembley-CSharp.dll and add this code either as a new class or as a function within existing class, like GameOverseer class. Make it static for simplicity purposes.

public static class ModImages
{

public static void AddSkillIcon()
{
Texture2D originalImage = ModIO.LoadImage(Application.dataPath + "\\Resources\\WL2_Icons.png");
Texture2D secondImage = ModIO.LoadImage(Application.dataPath + "\\Resources\\sneak.png");
Color[] bytes = originalImage.GetPixels(0, 0, originalImage.width, originalImage.height);
Color[] bytes2 = secondImage.GetPixels(0, 0, secondImage.width, secondImage.height);
Texture2D combinedImage = new Texture2D(originalImage.width, originalImage.height + 128);
combinedImage.SetPixels(0, 128, originalImage.width, originalImage.height, bytes, 0);
combinedImage.SetPixels(0, 0, secondImage.width, secondImage.height, bytes2, 0);
combinedImage.Apply();
byte[] bytes3 = combinedImage.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/Combined.png", bytes3);
UIAtlas iconAtlas = MonoBehaviourSingleton<GUIManager>.GetInstance(false).iconAtlas;
iconAtlas.spriteMaterial.mainTexture = combinedImage;
UISpriteData uispriteData = new UISpriteData();
uispriteData.name = "sneak";
uispriteData.SetRect(0, originalImage.height, 128, 128);
uispriteData.width = 128;
uispriteData.height = 128;
iconAtlas.spriteList.Add(uispriteData);
}
}
In short, we are loading original WL2_Icons.png and custom image (sneak.png here) at runtime and combine them in one new image. File.WriteAllBytes(Application.dataPath + "/Combined.png", bytes3) is here just to test it and see if combining went OK. If all went well you should get something like this:
Image

After combination we are createing new UiSpriteData and assigning important properties like name, position within big image ( uispriteData.SetRect(0, originalImage.height, 128, 128);) and size (width, height). Than we add that UISpriteData to instance of "iconAtlas" which must be instantiated exactly like in code above (Unity internal rules). Now, you need to call this function somwhere, and I did it in GameOverseer class within PreGameInit() function which looks like this:
public static void PreGameInit()
{
... (all existing code) +
ModImages.AddSkillIcon();
}
And that is it.
Start game and if yor skill sprite name corespond with name you gave it in code above, you should get
Image
or
Image

The name of Atlas is irelevant.
Obviously, you can skip runtime image combination mumbo jumbo and prepare WL2_Icons.png in Photoshop in advance keeping track of exact pixel position of your added sprite in mind. In that case your function will look like this:
public static class ModImages
{

public static void AddSkillIcon()
{

Texture2D combinedImage = ModIO.LoadImage(Application.dataPath + "\\Resources\\WL2_Icons.png");
UIAtlas iconAtlas = MonoBehaviourSingleton<GUIManager>.GetInstance(false).iconAtlas;
iconAtlas.spriteMaterial.mainTexture = combinedImage;
UISpriteData uispriteData = new UISpriteData();
uispriteData.name = "sneak";
uispriteData.SetRect(///pixel position X///, ///pixel position Y///, 128, 128); ///<-- x and y of starting position in big picture in pixels.
uispriteData.width = 128;
uispriteData.height = 128;
iconAtlas.spriteList.Add(uispriteData);
}
}
Path can be whatever you like, here it is in Resource directory (Application.dataPath + "\\Resources\\WL2_Icons.png");.

AliceInChains
Initiate
Posts: 3
Joined: April 14th, 2019, 2:50 am

Re: Wasteland 2: now with improved modding capabilities!

Post by AliceInChains » April 15th, 2019, 5:41 am

karlito31 wrote:
April 15th, 2019, 5:08 am
OK, here it is:
You will need dnSpy for this. Open Assembley-CSharp.dll and add this code either as a new class or as a function within existing class, like GameOverseer class. Make it static for simplicity purposes.
Great, many thanks! I am somewhat familiar with scripting/coding but not so much with this, so it probably would have taken me quite some time to figure out. Being able to adjust attributes, link them with skills, removing some of the current non-skills (like all ass skills, brute force), splitting/combining skills, and adding new ones will greatly improve the playability of this game. Being able to use different icons will definitely help with that, as having the same icons for different skills is a bit annoying.

Then again, being able to change all sorts of aspects in the game is exactly what's preventing me from just playing... Salutations and curses to you Executor_ :lol:

Executor_
Scholar
Posts: 207
Joined: August 11th, 2014, 5:38 am

Re: Wasteland 2: now with improved modding capabilities!

Post by Executor_ » April 15th, 2019, 6:00 am

0.9.4z now available here

MODDING
  • will now actually read the atlas field for Skills and Attributes; base game was always assuming WL2_Icons

Unless you're using karlito31's code, don't try to modify WL2_Icons, WL2_HUD, WL2_Equipment, etc. The exported MSONs for those files are only intended for reference purposes.

karlito31
Initiate
Posts: 7
Joined: March 16th, 2019, 12:46 am

Re: Wasteland 2: now with improved modding capabilities!

Post by karlito31 » April 15th, 2019, 6:15 am

Small addendum.
My presented function, in it's current form is totally crude. It can add only one icon with set hard coded name ("sneak" in this example) as a sprite name. One should expand it to read whole folder and collect all image names and place it in array, than combine them all and create as many sprites (UISpriteData) as there are image files in directory. I didnt need it so I left it as is. Anyway, here is latest 0.9.4z patch so no need for this at all. :)

InputEnd
Initiate
Posts: 1
Joined: April 16th, 2019, 10:36 pm

Re: Wasteland 2: now with improved modding capabilities!

Post by InputEnd » April 16th, 2019, 10:38 pm

Hi all, new to modding wasteland2, and need some help, my Assembly-Sharp.dll is larger than specified per the instructions, and the delta patcher keeps failing, what am I doing wrong, and how do I fix it?

Executor_
Scholar
Posts: 207
Joined: August 11th, 2014, 5:38 am

Re: Wasteland 2: now with improved modding capabilities!

Post by Executor_ » April 17th, 2019, 11:45 pm

Are you definitely using the Director's Cut version of the game? Also, what operating system (Windows/MacOS/Linus) are you playing on?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest