Jump to content

[WIP] [1.12.x] HUDReplacer - (v1.2.11-beta)


UltraJohn

Recommended Posts

HUDReplacer

HUDReplacer is a framework that allows you to replace the HUD/UI textures at runtime, without the hassle of modifying any stock files or assets.

The mod is currently a Work in Progress, so bugs may occur. It does not come with any custom textures out of the box, though an example config can be found on the github page for those who want to create their own.

This is intended as a dependency and a tool for modders to more easily create and share texture packs.

 

Example images:

3iZhJQy.png

yfQ8el3.png

 

Requirements:

Module Manager

HarmonyKSP

 

Download: 

Download-Github-green or Download-CKAN-green

 

Texture packs:

 

Send me a PM or leave a comment if you want your own texture pack featured above!

 

Threads of the month: May 2023

Edited by UltraJohn
Link to comment
Share on other sites

31 minutes ago, Nazalassa said:

You should include the example textures in the zips (currently they are only in the source code)

No, wait, you actually have to download the entire source code to get them.

Good point, thanks for the feedback. Added a separate download for the example texture pack mod!

Link to comment
Share on other sites

I've messed around quite a bit with HUDReplacer, and I think I already have a bug report...

 

I think I've found a pretty nasty issue, when HUDReplacer fetches the files from a config (filePath = GameData/ExampleMod/PluginData/ for example), it follows the path from the current directory, and not the KSP directory!
(the current directory is the directory (or folder) from where the game was launched, not necessary the KSP directory.)

For example, I have a shortcut on my desktop to launch KSP, so the directory from which KSP is launched is /home/whateverMyUserNameIs/ , so when HUDReplacer searches the directory GameData/ExampleMod/PluginData/, it actually looks at /home/whateverMyUserNameIs/GameData/ExampleMod/PluginData/ (which does not exist, as KSP isn't installed in /home/whateverMyUserNameIs/ ), and not at /home/whateverMyUserNameIs/Utility/KSP/GameData/ExampleMod/PluginData/ which is where it actually is.
I learned all that from KSP.log where it said something like this: error, can't find directory /home/whateverMyUserNameIs/GameData/ExampleMod/PluginData/ .

So, in order to load the images, I had to specify the following path: Utility/KSP/GameData/ExampleMod/PluginData/ ( /home/whateverMyUserNameIs/Utility/KSP/GameData/ExampleMod/PluginData/ also works). However, that makes texture packs (etc.) not portable, as different installs of KSP can be in different folders, and the current directory is not always the KSP directory, which is (at least in my opinion) a big issue.

 

--]  POSSIBLE PATCH  [--

After browsing HUDReplacer's source code, I think I found the culprit: in HUDReplacer.cs , line 113:
Directory.GetFiles(filePath, "*.png");

This function seems to looks for a directory that is either an absolute directory (path starts with C:\ or / for example), or a sub-directory of the "current directory". So, to fix that issue, the simplest idea would be perhaps to replace filepath by something like KSP_directory + filePath , and that would ensure that the mod loads correctly paths like GameData/ExampleMod/PluginData .

By looking at the source of Navball Texture Changer (file NavBallTextures.cs , line 88) (https://github.com/linuxgurugamer/NavBallTextureChanger/blob/master/Source/NavBallTexture.cs) I found that they used this:
KSPUtil.ApplicationRootPath + "GameData/NavBallTextureChanger/PluginData/"

So it appears that what we're searching is KSPUtil.ApplicationRootPath ! I don't know if you need to add something like using KSPUtils , but I found it in the KSP API (https://www.kerbalspaceprogram.com/ksp/api/class_k_s_p_util.html#a60726f2d6045af932ffa222c8473424e). So I guess you don't need to...

So, in a nutshell: a possible patch would be to replace Directory.GetFiles(filePath, "*.png"); by Directory.GetFiles(KSPUtil.ApplicationRootPath + filePath, "*.png"); .

 

Ah, one last thing: you should maybe update the readme to indicate that, in the developer version, pressing 'e' dumps all images loaded to the log and, most importantly, pressing 'q' refreshes the loaded images. (key-binds found in HUDReplacer.cs)

 

Nice mod btw. I can't wait to play KSP 95

Link to comment
Share on other sites

45 minutes ago, Nazalassa said:

I've messed around quite a bit with HUDReplacer, and I think I already have a bug report...

Nice mod btw. I can't wait to play KSP 95

Thank you for the feedback. I've added the proposed change and it should work now. If not, let me know.

Link to comment
Share on other sites

The fix works perfectly :)

I'm trying to get as much names as possible, and I propose that, for clarity, HUDReplacer prints a thick line ( [][][][][][][][][] ) to the log before spitting all the names when "d" is pressed, because else it's hard to make the difference between the outputs of two consecutive presses of "d" (if nothing's logged between them). Understand: it will improve readability if someone presses "d" a lot of times in a row.

I have made a pull request: https://github.com/UltraJohn/HUDReplacer/pull/1

 

Oh, btw, here's what I have been doing all the afternoon:

EZKpo57.png

I'm planning to make the, um, let's call it "theme", once I'll have done all the space center and VAB/SPH buttons.

Edited by Nazalassa
Fix works, yey
Link to comment
Share on other sites

32 minutes ago, UltraJohn said:

Approved and updated.

That's looking really awesome! I immediately got hit by some nostalgia!

Thanks :)
I think I'll make it a new theme for KSP (I have plenty of time to kill this week)

I just loaded all scenes and dumped the list of names of textures, then copied those that didn't start by Squad/ or something (those that aren't in GameData) to a new file, then sorted the file. Now I know all the names that are present in the scenes I loaded (settings, astronaut complex, VAB, etc.) so that if I find the name of one texture I can deduce the name of other textures.

(for the same thing. sorry if what I say is all but understandable)

Link to comment
Share on other sites

3 minutes ago, Nazalassa said:

Thanks :)
I think I'll make it a new theme for KSP (I have plenty of time to kill this week)

I just loaded all scenes and dumped the list of names of textures, then copied those that didn't start by Squad/ or something (those that aren't in GameData) to a new file, then sorted the file. Now I know all the names that are present in the scenes I loaded (settings, astronaut complex, VAB, etc.) so that if I find the name of one texture I can deduce the name of other textures.

(for the same thing. sorry if what I say is all but understandable)

Besides also using D to get the mouseover textures, you can use a 3rd party tool to get a list of all the internal texture names for easy referencing. I suspect you already know how to do this :)

It'll make it easy to know which textures exist at different sizes (they will have the same internal name in sharedassets but the width/height varies). 

 

Can't wait to see your progress!

Link to comment
Share on other sites

I'll do all that before anything else:

 NOTES
=======

Astronaut Complex
 -> Top bar:           mainBorder_top#6x33
 -> Crewmember bg:     vsd_widget_crew_bg#30x54
 -> Accept crewmember: vsd_widget_crew_button_v#22x54        (tick)
                       vsd_widget_crew_button_v_over#22x54   (tick)
                       vsd_widget_crew_button_v_down#22x54   (tick)
 -> Remove crewmember: vsd_widget_crew_button_x#22x54        (cross)
                       vsd_widget_crew_button_x_over#22x54   (cross)
                       vsd_widget_crew_button_x_down#22x54   (cross)
 -> Slider:            vsd_slider_fill#29x11
                       vsd_slider_bg#29x11
 -> Level:             lvl0#85x17
                       lvl1#85x17
                       lvl2#85x17
                       lvl3#85x17
                       lvl4#85x17
                       lvl5#85x17
 -> Suit switcher:     kerbal_switch_suit#32x32
 -> Tabs:              tab_std_normal#44x24
 ->


scrollbarVknow#16x182
scrollbarHknow#182x16

VAB:
Blue_Btn_Normal#40x18
Blue_Btn_Over#40x18
Blue_Btn_Active#40x18
Blue_Btn_Inactive#40x18
gen_btn_right_normal#22x32
gen_btn_right_over#22x32
gen_btn_right_active#22x32
gen_btn_right_inactive#22x32
gen_btn_left_normal#22x32
gen_btn_left_over#22x32
gen_btn_left_active#22x32
gen_btn_left_inactive#22x32
pin_toggle_on#32x32
pin_toggle_off#32x32
numeric_toggle_on#32x32
numeric_toggle_off#32x32
Flow_Enabled#18x18
Flow_Disabled#18x18

EditorButtons_New
EditorButtons_Load
EditorButtons_save
EditorButtons_Launch

EditorButtons_Symmetry_stateMap#384x256
EditorButtons_MirrorSymmetry_stateMap#128x256
EditorButtons_Symmetry_norm#128x128
EditorButtons_Symmetry_hover#128x128
EditorButtons_Symmetry_act#128x128
EditorButtons_Symmetry_disabled#128x128

app_divider_pulldown_header_xxx#30x17

Do you know the name of the texture for the grey bar on top of the screen? I couldn't find it.

Link to comment
Share on other sites

On 4/3/2023 at 7:02 PM, UltraJohn said:

Check the example mod files. Should be some of these:

KSCTopBar 1

KSCTopBar 3

KSCTopBar

KSCTopBarNew

That's for the KSC. But for the VAB/tracking station/etc. ? I can't find them.

Also is there a way to save a texture from the game into a png (or whatever) file?

Edited by Nazalassa
Link to comment
Share on other sites

Turns out you can change any internal image in the game, which apparently include fonts (???), the Navball (???), building (and planet) textures (???), "wernerVonKerman_head" (???), and...

laX7JGe.gif   UwTjgDP.gif

I never had so much fun :D

Link to comment
Share on other sites

1 hour ago, Nazalassa said:

If anyone wants to try it...

Nice!

Have you tested this on 1.7.x since you tagged it as a compatible version? I'm wondering if I should tag mine as that as well if it's confirmed to work on earlier versions.

Link to comment
Share on other sites

12 hours ago, UltraJohn said:

Have you tested this on 1.7.x since you tagged it as a compatible version? I'm wondering if I should tag mine as that as well if it's confirmed to work on earlier versions.

I did it yesterday, didn't work but turns out I had an incompatible version of MM installed. I'm retrying rn

Nah, it doesn't, here's an error in KSP.log:

	[LOG 08:27:27.864] Load(Assembly): HUDReplacer-dev/HUDReplacer
[LOG 08:27:27.864] AssemblyLoader: Loading assembly at /home/ivyroot/Backups/KSP_linux/GameData/HUDReplacer-dev/HUDReplacer.dll
[LOG 08:27:27.867] AssemblyLoader: Loading assemblies
[ERR 08:27:27.909] ADDON BINDER: Cannot resolve assembly: UnityEngine.CoreModule, Culture=neutral, PublicKeyToken=null
	[ERR 08:27:27.909] ADDON BINDER: Cannot resolve assembly: UnityEngine.CoreModule, Culture=neutral, PublicKeyToken=null
	[ERR 08:27:27.911] AssemblyLoader: Exception loading 'HUDReplacer': System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
  at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
  at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0
  at AssemblyLoader.LoadAssemblies () [0x00000] in <filename unknown>:0
	Additional information about this exception:
	 System.IO.FileNotFoundException: Could not load file or assembly 'UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
	 System.TypeLoadException: Could not load type 'HUDReplacer.HUDReplacer' from assembly 'HUDReplacer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
	 System.TypeLoadException: Could not load type 'HUDReplacer.HUDReplacer' from assembly 'HUDReplacer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
	 System.TypeLoadException: Could not load type '<>c' from assembly 'HUDReplacer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
	

So I guess that's our culprit:

UnityEngine.CoreModule

Does the mod work without it? (like removing the "using UnityEngine.CoreModule")

Link to comment
Share on other sites

5 hours ago, Nazalassa said:

I mean removing the "using UnityEngine.CoreModule"s from the source code and recompiling

Nah you can't remove the core module. I guess it's incompatible with 1.7.x then.

I was only targeting 1.12.x to begin with, so any version earlier would be a bonus. You can try newer versions if you want and let me know how it goes.

Link to comment
Share on other sites

3 hours ago, Nazalassa said:

I think HUDReplacer requires MM right? As the configs use MM syntax (:NEEDS[HUDReplacer])

Technically the framework won't require it, as it doesnt come with any config by default. Only the texture packs that people download needs to add the :NEEDS[HUDReplacer] to their config if you want to make sure that it only loads if the framework is installed. You could in theory remove the NEEDS part from the config and it would still work without MM I think.

So, there's two options here.

1. I add MM as a dependency for the framework and therefore texture packs won't need to specify they need it as well.

2. I let texture packs have the dependency included instead.

I think going with option 1 makes more sense, so I will update my post with the required dependency.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...