1111import java .nio .Buffer ;
1212import java .nio .ByteBuffer ;
1313import java .nio .ByteOrder ;
14+ import java .util .LinkedList ;
15+ import java .util .List ;
1416
1517import javax .imageio .ImageIO ;
1618
@@ -31,20 +33,38 @@ public final class ImageUtils {
3133 public static final String DEFAULT_ICON_PATH = "ReplaceableTextures\\ CommandButtons\\ BTNTemp.blp" ;
3234
3335 public static Texture getAnyExtensionTexture (final DataSource dataSource , final String path ) {
34- if (dataSource .has (path )) {
35- BufferedImage image ;
36- try {
37- final AnyExtensionImage imageInfo = getAnyExtensionImageFixRGB (dataSource , path , "texture" );
38- image = imageInfo .getImageData ();
39- if (image != null ) {
40- return ImageUtils .getTexture (image , imageInfo .isNeedsSRGBFix ());
36+ final List <String > paths = new LinkedList <>(List .of (path ));
37+
38+ if (path .length () >= 4 ) {
39+ final String extension = path .substring (path .length () - 4 ).toLowerCase ();
40+
41+ if (!".dds" .equals (extension )) {
42+ // Reforged has TeamColors etc. as DDS files only.
43+ paths .add (path .substring (0 , path .length () - 4 ) + ".dds" );
44+ }
45+
46+ if (!".blp" .equals (extension )) {
47+ paths .add (path .substring (0 , path .length () - 4 ) + ".blp" );
48+ }
49+ }
50+
51+ for (String p : paths ) {
52+ if (dataSource .has (p )) {
53+ BufferedImage image ;
54+ try {
55+ final AnyExtensionImage imageInfo = getAnyExtensionImageFixRGB (dataSource , p , "texture" );
56+ image = imageInfo .getImageData ();
57+ if (image != null ) {
58+ return ImageUtils .getTexture (image , imageInfo .isNeedsSRGBFix ());
59+ }
60+ } catch (final IOException e ) {
61+ return null ;
4162 }
42- } catch (final IOException e ) {
43- return null ;
4463 }
45- } else {
46- System .err .println ("Missing texture " + path );
4764 }
65+
66+ System .err .println ("Missing texture " + path + " tried paths: " + String .join ("," , paths ));
67+
4868 return null ;
4969 }
5070
0 commit comments