@@ -27,25 +27,20 @@ public override TMP_FontAsset Create(Type objectType)
2727 internal class LanguageSupport : Mod
2828 {
2929 internal static LanguageSupport Instance ;
30- private readonly string DIR ;
30+ private readonly string _dir ;
3131
32- private readonly string FOLDER = "LanguageSupport" ;
32+ private readonly string _folder = "LanguageSupport" ;
3333
3434 public LanguageSupport ( ) : base ( "Language Support" )
3535 {
3636 Instance = this ;
3737
38- switch ( SystemInfo . operatingSystemFamily )
38+ _dir = Path . Combine ( Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ?? throw new DirectoryNotFoundException ( "I have no idea how you did this, but good luck figuring it out." ) , _folder ) ;
39+
40+ if ( ! Directory . Exists ( _dir ) )
3941 {
40- case OperatingSystemFamily . MacOSX :
41- DIR = Path . GetFullPath ( Application . dataPath + "/Resources/Data/Managed/Mods/" + FOLDER ) ;
42- break ;
43- default :
44- DIR = Path . GetFullPath ( Application . dataPath + "/Managed/Mods/" + FOLDER ) ;
45- break ;
42+ Directory . CreateDirectory ( _dir ) ;
4643 }
47-
48- if ( ! Directory . Exists ( DIR ) ) Directory . CreateDirectory ( DIR ) ;
4944 }
5045
5146 public override string GetVersion ( )
@@ -103,32 +98,32 @@ private void OnTMP_FontAssetReadFontDefinition(On.TMPro.TMP_FontAsset.orig_ReadF
10398
10499 private void OnTextMeshProLoadFontAsset ( On . TMPro . TextMeshPro . orig_LoadFontAsset orig , TextMeshPro self )
105100 {
106- var m_fontAsset = self . GetAttr < TextMeshPro , TMP_FontAsset > ( "m_fontAsset" ) ;
107- var m_renderer = self . GetAttr < TextMeshPro , Renderer > ( "m_renderer" ) ;
108- var m_sharedMaterial = self . GetAttr < TextMeshPro , Material > ( "m_sharedMaterial" ) ;
101+ var mFontAsset = self . GetAttr < TextMeshPro , TMP_FontAsset > ( "m_fontAsset" ) ;
102+ var mRenderer = self . GetAttr < TextMeshPro , Renderer > ( "m_renderer" ) ;
103+ var mSharedMaterial = self . GetAttr < TextMeshPro , Material > ( "m_sharedMaterial" ) ;
109104
110- if ( m_fontAsset . name == "noto_serif_thai_bold_tmpro" )
105+ if ( mFontAsset . name == "noto_serif_thai_bold_tmpro" )
111106 {
112- Log ( $ "OnTextMeshProLoadFontAsset - { m_fontAsset . characterDictionary } ") ; // ""
113- if ( m_fontAsset . characterDictionary == null )
107+ Log ( $ "OnTextMeshProLoadFontAsset - { mFontAsset . characterDictionary } ") ; // ""
108+ if ( mFontAsset . characterDictionary == null )
114109 {
115- m_fontAsset . ReadFontDefinition ( ) ;
110+ mFontAsset . ReadFontDefinition ( ) ;
116111 }
117- Log ( $ "OnTextMeshProLoadFontAsset - { m_fontAsset . characterDictionary } ") ; // ""
118- Log ( $ "OnTextMeshProLoadFontAsset - { m_renderer . sharedMaterial } ") ; // "perpetua_tmpro Material (UnityEngine.Material)"
119- Log ( $ "OnTextMeshProLoadFontAsset - { m_renderer . sharedMaterial . mainTexture } ") ; // "perpetua_tmpro Atlas (UnityEngine.Texture2D)"
120- Log ( $ "OnTextMeshProLoadFontAsset - { m_fontAsset . atlas } ") ; // ""
121- Log ( $ "OnTextMeshProLoadFontAsset - { m_fontAsset . material } ") ;
122- Log ( $ "OnTextMeshProLoadFontAsset - { m_renderer . receiveShadows } ") ;
123- Log ( $ "OnTextMeshProLoadFontAsset - { m_renderer . shadowCastingMode } ") ;
112+ Log ( $ "OnTextMeshProLoadFontAsset - { mFontAsset . characterDictionary } ") ; // ""
113+ Log ( $ "OnTextMeshProLoadFontAsset - { mRenderer . sharedMaterial } ") ; // "perpetua_tmpro Material (UnityEngine.Material)"
114+ Log ( $ "OnTextMeshProLoadFontAsset - { mRenderer . sharedMaterial . mainTexture } ") ; // "perpetua_tmpro Atlas (UnityEngine.Texture2D)"
115+ Log ( $ "OnTextMeshProLoadFontAsset - { mFontAsset . atlas } ") ; // ""
116+ Log ( $ "OnTextMeshProLoadFontAsset - { mFontAsset . material } ") ;
117+ Log ( $ "OnTextMeshProLoadFontAsset - { mRenderer . receiveShadows } ") ;
118+ Log ( $ "OnTextMeshProLoadFontAsset - { mRenderer . shadowCastingMode } ") ;
124119 }
125120
126121 orig ( self ) ;
127122 }
128123
129- private static AssetBundle abFa = null ;
130- private static TMP_FontAsset fa = null ;
131- private static Sprite atlas = null ;
124+ private static AssetBundle _abFa = null ;
125+ private static TMP_FontAsset _fa = null ;
126+ private static Sprite _atlas = null ;
132127
133128 private void OnChangeFontByLanguageSetFont ( On . ChangeFontByLanguage . orig_SetFont orig , ChangeFontByLanguage self )
134129 {
@@ -144,7 +139,7 @@ private void OnChangeFontByLanguageSetFont(On.ChangeFontByLanguage.orig_SetFont
144139
145140 if ( json )
146141 {
147- if ( fa == null )
142+ if ( _fa == null )
148143 {
149144 Log ( 3 ) ;
150145 Assembly asm = Assembly . GetExecutingAssembly ( ) ;
@@ -165,15 +160,15 @@ private void OnChangeFontByLanguageSetFont(On.ChangeFontByLanguage.orig_SetFont
165160 string jsonText = System . Text . Encoding . UTF8 . GetString ( buffer ) ;
166161
167162 Log ( 10 ) ;
168- fa = JsonConvert . DeserializeObject < TMP_FontAsset > ( jsonText , new TmpFontConverter ( ) ) ;
163+ _fa = JsonConvert . DeserializeObject < TMP_FontAsset > ( jsonText , new TmpFontConverter ( ) ) ;
169164 Log ( 10.5 ) ;
170- fa . name = "noto_serif_thai_bold_tmpro" ;
165+ _fa . name = "noto_serif_thai_bold_tmpro" ;
171166 Log ( 11 ) ;
172- Object . DontDestroyOnLoad ( fa ) ;
167+ Object . DontDestroyOnLoad ( _fa ) ;
173168 }
174169
175- fa . atlas = null ; // texture2d
176- fa . material = new Material ( Shader . Find ( "GUI/Text Shader" ) ) ;
170+ _fa . atlas = null ; // texture2d
171+ _fa . material = new Material ( Shader . Find ( "GUI/Text Shader" ) ) ;
177172
178173 using ( Stream s = asm . GetManifestResourceStream ( "LanguageSupport.Resources.noto_serif_thai_bold.png" ) )
179174 {
@@ -190,20 +185,20 @@ private void OnChangeFontByLanguageSetFont(On.ChangeFontByLanguage.orig_SetFont
190185
191186 // Create sprite from texture
192187 // Split is to cut off the DreamKing.Resources. and the .png
193- atlas = Sprite . Create ( tex , new Rect ( 0 , 0 , tex . width , tex . height ) , new Vector2 ( 0.5f , 0.5f ) ) ;
194- Object . DontDestroyOnLoad ( atlas ) ;
188+ _atlas = Sprite . Create ( tex , new Rect ( 0 , 0 , tex . width , tex . height ) , new Vector2 ( 0.5f , 0.5f ) ) ;
189+ Object . DontDestroyOnLoad ( _atlas ) ;
195190 }
196191 }
197- fa . material . SetTexture ( "_MainTex" , atlas . texture ) ;
198- fa . atlas = atlas . texture ;
192+ _fa . material . SetTexture ( "_MainTex" , _atlas . texture ) ;
193+ _fa . atlas = _atlas . texture ;
199194
200- fa . material . SetColor ( "_Color" , Color . white ) ;
195+ _fa . material . SetColor ( "_Color" , Color . white ) ;
201196 }
202197
203- if ( fa != null )
198+ if ( _fa != null )
204199 {
205200 Log ( 20 ) ;
206- self . GetAttr < ChangeFontByLanguage , TextMeshPro > ( "tmpro" ) . font = fa ;
201+ self . GetAttr < ChangeFontByLanguage , TextMeshPro > ( "tmpro" ) . font = _fa ;
207202 //var tmp = self.GetAttr<ChangeFontByLanguage, TextMeshPro>("tmpro");
208203 //Log(21);
209204 //tmp.font = fa;
@@ -213,7 +208,7 @@ private void OnChangeFontByLanguageSetFont(On.ChangeFontByLanguage.orig_SetFont
213208 }
214209 else
215210 {
216- if ( abFa == null )
211+ if ( _abFa == null )
217212 {
218213 Log ( 12 ) ;
219214 Assembly asm = Assembly . GetExecutingAssembly ( ) ;
@@ -224,30 +219,30 @@ private void OnChangeFontByLanguageSetFont(On.ChangeFontByLanguage.orig_SetFont
224219 if ( s == null ) return ;
225220
226221 Log ( 15 ) ;
227- abFa = AssetBundle . LoadFromStream ( s ) ;
222+ _abFa = AssetBundle . LoadFromStream ( s ) ;
228223 Log ( 16 ) ;
229- Object . DontDestroyOnLoad ( abFa ) ;
224+ Object . DontDestroyOnLoad ( _abFa ) ;
230225 }
231226 }
232227
233228 Log ( 17 ) ;
234229
235- if ( fa == null && abFa != null )
230+ if ( _fa == null && _abFa != null )
236231 {
237232 Log ( 18 ) ;
238- fa = abFa . LoadAsset < TMP_FontAsset > ( "noto_serif_thai_bold.asset" ) ;
233+ _fa = _abFa . LoadAsset < TMP_FontAsset > ( "noto_serif_thai_bold.asset" ) ;
239234 Log ( 18.5 ) ;
240- fa . name = "noto_serif_thai_bold_tmpro" ;
235+ _fa . name = "noto_serif_thai_bold_tmpro" ;
241236 Log ( 19 ) ;
242- Object . DontDestroyOnLoad ( fa ) ;
237+ Object . DontDestroyOnLoad ( _fa ) ;
243238 }
244239
245- if ( fa != null )
240+ if ( _fa != null )
246241 {
247242 Log ( 20 ) ;
248243 var tmp = ( TextMeshPro ) typeof ( ChangeFontByLanguage ) . GetField ( "tmpro" , BindingFlags . Instance | BindingFlags . NonPublic ) . GetValue ( self ) ;
249244 Log ( 21 ) ;
250- tmp . font = fa ;
245+ tmp . font = _fa ;
251246 Log ( 22 ) ;
252247 typeof ( ChangeFontByLanguage ) . GetField ( "tmpro" , BindingFlags . Instance | BindingFlags . NonPublic ) . SetValue ( self , tmp ) ;
253248 }
@@ -270,7 +265,7 @@ private void InitLanguage()
270265 {
271266 #region Dump English Files
272267
273- if ( ! Directory . Exists ( $ "{ DIR } /EN") ) Directory . CreateDirectory ( $ "{ DIR } /EN") ;
268+ if ( ! Directory . Exists ( $ "{ _dir } /EN") ) Directory . CreateDirectory ( $ "{ _dir } /EN") ;
274269 string [ ] sheets =
275270 {
276271 "Achievements" ,
@@ -311,10 +306,10 @@ private void InitLanguage()
311306 "Zote"
312307 } ;
313308 foreach ( var sheet in sheets )
314- if ( ! File . Exists ( $ "{ DIR } /EN/{ sheet } .txt") )
309+ if ( ! File . Exists ( $ "{ _dir } /EN/{ sheet } .txt") )
315310 {
316311 var t = ( ( TextAsset ) Resources . Load ( $ "Languages/EN_{ sheet } ", typeof ( TextAsset ) ) ) . text ;
317- using ( var outputFile = new StreamWriter ( $ "{ DIR } /EN/{ sheet } .txt") )
312+ using ( var outputFile = new StreamWriter ( $ "{ _dir } /EN/{ sheet } .txt") )
318313 {
319314 outputFile . Write ( t ) ;
320315 }
@@ -343,7 +338,7 @@ private bool OnLanguageHasLanguageFile(On.Language.Language.orig_HasLanguageFile
343338 var ret = orig ( lang , sheetTitle ) ;
344339 if ( ! ret )
345340 {
346- if ( File . Exists ( $ "{ DIR } /{ lang } /{ sheetTitle } .txt") )
341+ if ( File . Exists ( $ "{ _dir } /{ lang } /{ sheetTitle } .txt") )
347342 {
348343 ret = true ;
349344 }
@@ -356,9 +351,9 @@ private string OnLanguageGetLanguageFileContents(On.Language.Language.orig_GetLa
356351 string ret = orig ( sheetTitle ) ;
357352 if ( ret == string . Empty )
358353 {
359- if ( File . Exists ( $ "{ DIR } /{ Language . Language . CurrentLanguage ( ) } /{ sheetTitle } .txt") )
354+ if ( File . Exists ( $ "{ _dir } /{ Language . Language . CurrentLanguage ( ) } /{ sheetTitle } .txt") )
360355 {
361- return File . ReadAllText ( $ "{ DIR } /{ Language . Language . CurrentLanguage ( ) } /{ sheetTitle } .txt") ;
356+ return File . ReadAllText ( $ "{ _dir } /{ Language . Language . CurrentLanguage ( ) } /{ sheetTitle } .txt") ;
362357 }
363358 }
364359 return ret ;
@@ -382,7 +377,7 @@ private void OnMenuLanguageSettingRefreshAvailableLanguages(On.UnityEngine.UI.Me
382377
383378 foreach ( var l in customLangs )
384379 {
385- if ( File . Exists ( $ "{ DIR } /{ l } /General.txt") || ( langs . Contains ( ( SupportedLanguages ) l ) ) )
380+ if ( File . Exists ( $ "{ _dir } /{ l } /General.txt") || ( langs . Contains ( ( SupportedLanguages ) l ) ) )
386381 {
387382 finalLangs . Add ( ( SupportedLanguages ) l ) ;
388383 }
0 commit comments