@@ -17,6 +17,7 @@ public abstract class ModBase
17
17
{
18
18
public List < Texture2D > ModTextures { get ; protected set ; }
19
19
public List < GameObject > ModObjects { get ; protected set ; }
20
+ public Assembly ModAssembly { get ; protected set ; } // This is set by the mod loader and should generally not be set elsewhere except possibly by second stage mod loaders
20
21
21
22
public virtual Version ModVersion => new Version ( 0 , 0 , 0 , 0 ) ;
22
23
@@ -25,22 +26,28 @@ public abstract class ModBase
25
26
private static FastZip ZipInstance { get ; } = new FastZip ( ) ;
26
27
27
28
protected ModBase ( )
29
+ {
30
+ ExtractAssemblyResources ( ) ;
31
+ LoadResourcesSafe ( ) ;
32
+ UpdateCredits ( ) ;
33
+ }
34
+
35
+ protected virtual void ExtractAssemblyResources ( )
28
36
{
29
37
//Extract embedded assets
30
38
ZipConstants . DefaultCodePage = 0 ; //This is a workaround to get files to extract properly
31
39
32
- var currentAssembly = Assembly . GetCallingAssembly ( ) ;
33
- var manifest = currentAssembly . GetManifestResourceNames ( ) ;
34
-
35
- PreProcessEmbeddedResources ( manifest ) ;
40
+ var manifestResources = ModAssembly . GetManifestResourceNames ( ) ;
41
+ PreProcessEmbeddedResources ( manifestResources ) ;
36
42
37
- foreach ( var file in manifest )
43
+ foreach ( var file in manifestResources )
38
44
{
39
- if ( ! PreProcessEmbeddedResource ( file ) ) continue ;
45
+ if ( ! PreProcessEmbeddedResource ( file ) )
46
+ continue ;
40
47
41
48
Debug . Log ( $ "Processing embedded file \" { file } \" ") ;
42
49
43
- using ( var resourceStream = currentAssembly . GetManifestResourceStream ( file ) )
50
+ using ( var resourceStream = ModAssembly . GetManifestResourceStream ( file ) )
44
51
{
45
52
switch ( Path . GetExtension ( file ) )
46
53
{
@@ -73,7 +80,17 @@ protected ModBase()
73
80
}
74
81
}
75
82
}
83
+ }
84
+
85
+ protected virtual void LoadResourcesSafe ( )
86
+ {
87
+ LoadStringsSafe ( ) ;
88
+ LoadPngsSafe ( ) ;
89
+ LoadObjsSafe ( ) ;
90
+ }
76
91
92
+ protected virtual void LoadStringsSafe ( )
93
+ {
77
94
try
78
95
{
79
96
LoadAllStrings ( "strings" ) ;
@@ -83,7 +100,10 @@ protected ModBase()
83
100
Debug . Log ( "Failed to load strings files due to exception:" ) ;
84
101
Utils . LogException ( e ) ;
85
102
}
103
+ }
86
104
105
+ protected virtual void LoadPngsSafe ( )
106
+ {
87
107
try
88
108
{
89
109
ModTextures = LoadAllPngs ( "png" ) ;
@@ -98,12 +118,15 @@ protected ModBase()
98
118
Debug . Log ( "Failed to load PNG files due to exception:" ) ;
99
119
Utils . LogException ( e ) ;
100
120
}
121
+ }
101
122
123
+ protected virtual void LoadObjsSafe ( )
124
+ {
102
125
try
103
126
{
104
127
ModObjects = LoadAllObjs ( "obj" ) ;
105
128
106
- if ( ModObjects . Count > 0 )
129
+ if ( ModObjects . Count > 0 )
107
130
{
108
131
Debug . Log ( $ "Successfully loaded { ModObjects . Count } object(s)") ;
109
132
}
@@ -113,8 +136,11 @@ protected ModBase()
113
136
Debug . Log ( "Failed to load OBJ files due to exception:" ) ;
114
137
Utils . LogException ( e ) ;
115
138
}
139
+ }
116
140
117
- var credits = GetCredits ( ) . Trim ( ) ;
141
+ protected virtual void UpdateCredits ( )
142
+ {
143
+ var credits = GetCredits ( ) ? . Trim ( ) ;
118
144
if ( ! string . IsNullOrEmpty ( credits ) )
119
145
ConstructorPatch . Credits [ this ] = credits ;
120
146
}
0 commit comments