@@ -7,7 +7,10 @@ public static class AssetManager
77 public static string BundlePath { get ; private set ; }
88
99 public static GameManifest Manifest { get ; private set ; }
10- private const string ManifestPath = "assets/manifest.asset" ;
10+
11+ public const string ManifestPath = "assets/manifest.asset" ;
12+ public const string AssetDumpPath = "AssetDump.txt" ;
13+ public const string MaterialsListPath = "MaterialsList.txt" ;
1114
1215 public static AssetBundleManifest AssetManifest { get ; private set ; }
1316
@@ -18,6 +21,8 @@ public static class AssetManager
1821 public static Dictionary < string , AssetBundle > AssetPaths { get ; private set ; } = new Dictionary < string , AssetBundle > ( System . StringComparer . OrdinalIgnoreCase ) ;
1922 public static Dictionary < string , Object > Cache { get ; private set ; } = new Dictionary < string , Object > ( ) ;
2023
24+ public static List < string > ManifestStrings { get => IsInitialised ? GetManifestStrings ( ) : new List < string > ( ) ; private set => ManifestStrings = value ; }
25+
2126 public static bool IsInitialised { get ; private set ; }
2227
2328 /// <summary>Loads the prefabs from the Rust prefab bundle.</summary>
@@ -32,7 +37,7 @@ public static void Initialise(string bundlesRoot)
3237 return ;
3338 }
3439
35- if ( ! SettingsManager . RustDirectory . EndsWith ( "Rust" ) )
40+ if ( ! SettingsManager . RustDirectory . EndsWith ( "Rust" ) && ! SettingsManager . RustDirectory . EndsWith ( "RustStaging" ) )
3641 {
3742 Debug . LogError ( "Not a valid Rust install directory: " + SettingsManager . RustDirectory ) ;
3843 return ;
@@ -70,6 +75,8 @@ public static void Initialise(string bundlesRoot)
7075 Bundles . Add ( bundles [ i ] , asset ) ;
7176 foreach ( var filename in asset . GetAllAssetNames ( ) )
7277 AssetPaths . Add ( filename , asset ) ;
78+ foreach ( var filename in asset . GetAllScenePaths ( ) )
79+ AssetPaths . Add ( filename , asset ) ;
7380 }
7481
7582 Manifest = GetAsset < GameManifest > ( ManifestPath ) ;
@@ -88,9 +95,10 @@ public static void Initialise(string bundlesRoot)
8895
8996 AssetDump ( ) ;
9097 rootBundle . Unload ( true ) ;
98+ FixMaterials ( ) ;
9199 IsInitialised = true ;
100+
92101 ProgressBarManager . Clear ( ) ;
93-
94102 PrefabManager . ReplaceWithLoaded ( PrefabManager . PrefabParent . GetComponentsInChildren < PrefabDataHolder > ( ) ) ;
95103 }
96104 else
@@ -99,9 +107,7 @@ public static void Initialise(string bundlesRoot)
99107
100108 private static T GetAsset < T > ( string filePath ) where T : Object
101109 {
102- AssetBundle bundle = null ;
103-
104- if ( ! AssetPaths . TryGetValue ( filePath , out bundle ) )
110+ if ( ! AssetPaths . TryGetValue ( filePath , out AssetBundle bundle ) )
105111 return null ;
106112
107113 return bundle . LoadAsset < T > ( filePath ) ;
@@ -170,7 +176,7 @@ public static List<string> GetManifestStrings()
170176 /// <summary>Dumps every asset found in the Rust content bundle to a text file.</summary>
171177 public static void AssetDump ( )
172178 {
173- using ( StreamWriter streamWriter = new StreamWriter ( "AssetDump.txt" , false ) )
179+ using ( StreamWriter streamWriter = new StreamWriter ( AssetDumpPath , false ) )
174180 foreach ( var item in AssetPaths . Keys )
175181 streamWriter . WriteLine ( item + " : " + ToID ( item ) ) ;
176182 }
@@ -179,8 +185,7 @@ public static string ToPath(uint i)
179185 {
180186 if ( ( int ) i == 0 )
181187 return i . ToString ( ) ;
182- string str ;
183- if ( IDLookup . TryGetValue ( i , out str ) )
188+ if ( IDLookup . TryGetValue ( i , out string str ) )
184189 return str ;
185190 return i . ToString ( ) ;
186191 }
@@ -189,9 +194,85 @@ public static uint ToID(string str)
189194 {
190195 if ( string . IsNullOrEmpty ( str ) )
191196 return 0 ;
192- uint num ;
193- if ( PathLookup . TryGetValue ( str , out num ) )
197+ if ( PathLookup . TryGetValue ( str , out uint num ) )
194198 return num ;
195199 return 0 ;
196200 }
201+
202+ /// <summary>Sets materials set in the MaterialsList.txt to the shader supplied. Used for certain prefabs which appear black due to the Rust shaders not having
203+ /// all of the dependencies needed to function properly in the project.</summary>
204+ public static void FixMaterials ( )
205+ {
206+ Shader std = Shader . Find ( "Standard" ) ;
207+ Shader spc = Shader . Find ( "Standard (Specular setup)" ) ;
208+
209+ if ( File . Exists ( MaterialsListPath ) )
210+ {
211+ foreach ( var item in File . ReadAllLines ( MaterialsListPath ) )
212+ {
213+ var lineSplit = item . Split ( ':' ) ;
214+ lineSplit [ 0 ] = lineSplit [ 0 ] . Trim ( ' ' ) ; // Shader Name
215+ lineSplit [ 1 ] = lineSplit [ 1 ] . Trim ( ' ' ) ; // Material Path
216+ switch ( lineSplit [ 0 ] )
217+ {
218+ case "Standard" :
219+ UpdateShader ( LoadAsset < Material > ( lineSplit [ 1 ] ) , std ) ;
220+ break ;
221+ case "Specular" :
222+ UpdateShader ( LoadAsset < Material > ( lineSplit [ 1 ] ) , spc ) ;
223+ break ;
224+ }
225+ }
226+ }
227+ LoadAsset < Material > ( @"assets/content/nature/overgrowth/models/materials/overgrowth.mat" ) . DisableKeyword ( "_TINTENABLED_ON" ) ; // Fix for overgrowth materials.
228+ }
229+
230+ /// <summary>Updates the material with the new shaders properties.</summary>
231+ private static void UpdateShader ( Material mat , Shader shader )
232+ {
233+ mat . shader = shader ;
234+ switch ( mat . GetFloat ( "_Mode" ) )
235+ {
236+ case 0f :
237+ mat . SetOverrideTag ( "RenderType" , "" ) ;
238+ mat . SetInt ( "_SrcBlend" , ( int ) UnityEngine . Rendering . BlendMode . One ) ;
239+ mat . SetInt ( "_DstBlend" , ( int ) UnityEngine . Rendering . BlendMode . Zero ) ;
240+ mat . SetInt ( "_ZWrite" , 1 ) ;
241+ mat . DisableKeyword ( "_ALPHATEST_ON" ) ;
242+ mat . DisableKeyword ( "_ALPHABLEND_ON" ) ;
243+ mat . DisableKeyword ( "_ALPHAPREMULTIPLY_ON" ) ;
244+ mat . renderQueue = - 1 ;
245+ break ;
246+ case 1f :
247+ mat . SetOverrideTag ( "RenderType" , "TransparentCutout" ) ;
248+ mat . SetInt ( "_SrcBlend" , ( int ) UnityEngine . Rendering . BlendMode . One ) ;
249+ mat . SetInt ( "_DstBlend" , ( int ) UnityEngine . Rendering . BlendMode . Zero ) ;
250+ mat . SetInt ( "_ZWrite" , 1 ) ;
251+ mat . EnableKeyword ( "_ALPHATEST_ON" ) ;
252+ mat . DisableKeyword ( "_ALPHABLEND_ON" ) ;
253+ mat . DisableKeyword ( "_ALPHAPREMULTIPLY_ON" ) ;
254+ mat . renderQueue = ( int ) UnityEngine . Rendering . RenderQueue . AlphaTest ;
255+ break ;
256+ case 2f :
257+ mat . SetOverrideTag ( "RenderType" , "Transparent" ) ;
258+ mat . SetInt ( "_SrcBlend" , ( int ) UnityEngine . Rendering . BlendMode . SrcAlpha ) ;
259+ mat . SetInt ( "_DstBlend" , ( int ) UnityEngine . Rendering . BlendMode . OneMinusSrcAlpha ) ;
260+ mat . SetInt ( "_ZWrite" , 0 ) ;
261+ mat . DisableKeyword ( "_ALPHATEST_ON" ) ;
262+ mat . EnableKeyword ( "_ALPHABLEND_ON" ) ;
263+ mat . DisableKeyword ( "_ALPHAPREMULTIPLY_ON" ) ;
264+ mat . renderQueue = ( int ) UnityEngine . Rendering . RenderQueue . Transparent ;
265+ break ;
266+ case 3f :
267+ mat . SetOverrideTag ( "RenderType" , "Transparent" ) ;
268+ mat . SetInt ( "_SrcBlend" , ( int ) UnityEngine . Rendering . BlendMode . One ) ;
269+ mat . SetInt ( "_DstBlend" , ( int ) UnityEngine . Rendering . BlendMode . OneMinusSrcAlpha ) ;
270+ mat . SetInt ( "_ZWrite" , 0 ) ;
271+ mat . DisableKeyword ( "_ALPHATEST_ON" ) ;
272+ mat . DisableKeyword ( "_ALPHABLEND_ON" ) ;
273+ mat . EnableKeyword ( "_ALPHAPREMULTIPLY_ON" ) ;
274+ mat . renderQueue = ( int ) UnityEngine . Rendering . RenderQueue . Transparent ;
275+ break ;
276+ }
277+ }
197278}
0 commit comments