public override void Initialize(Harmony plibInstance) { UI.TextMeshProPatcher.Patch(); var ugc = PPatchTools.GetTypeSafe("SteamUGCService", "Assembly-CSharp"); if (ugc != null) { try { plibInstance.PatchTranspile(ugc, "LoadPreviewImage", PatchMethod(nameof( LoadPreviewImage_Transpile))); } catch (Exception e) { #if DEBUG PUtil.LogExcWarn(e); #endif } } plibInstance.Patch(typeof(Localization), nameof(Localization.Initialize), postfix: PatchMethod(nameof(Initialize_Postfix))); }
/// <summary> /// Localizes the PLib strings. /// </summary> /// <param name="locale">The locale to use.</param> internal static void LocalizeItself(Localization.Locale locale) { if (locale == null) { throw new ArgumentNullException(nameof(locale)); } Localization.RegisterForTranslation(typeof(PLibStrings)); var assembly = Assembly.GetExecutingAssembly(); string locCode = locale.Code; if (string.IsNullOrEmpty(locCode)) { locCode = Localization.GetCurrentLanguageCode(); } try { using (var stream = assembly.GetManifestResourceStream( TRANSLATIONS_RES_PATH + locCode + TRANSLATIONS_EXT)) { if (stream != null) { // File.ReadAllLines does not work on streams unfortunately var lines = new List <string>(128); using (var reader = new StreamReader(stream, Encoding.UTF8)) { string line; while ((line = reader.ReadLine()) != null) { lines.Add(line); } } Localization.OverloadStrings(Localization.ExtractTranslatedStrings( lines.ToArray())); #if DEBUG PUtil.LogDebug("Localizing PLib Core to locale {0}".F(locCode)); #endif } } } catch (Exception e) { PUtil.LogWarning("Failed to load {0} localization for PLib Core:".F(locCode)); PUtil.LogExcWarn(e); } }
/// <summary> /// Retrieves a type using its full name (including namespace). However, the assembly /// name is optional, as this method searches all assemblies in the current /// AppDomain if it is null or empty. /// </summary> /// <param name="name">The type name to retrieve.</param> /// <param name="assemblyName">If specified, the name of the assembly that contains /// the type. No other assembly name will be searched if this parameter is not null /// or empty. The assembly name might not match the DLL name, use a decompiler to /// make sure.</param> /// <returns>The type, or null if the type is not found or cannot be loaded.</returns> public static Type GetTypeSafe(string name, string assemblyName = null) { Type type = null; if (string.IsNullOrEmpty(assemblyName)) { foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { try { type = assembly.GetType(name, false); } catch (System.IO.IOException) { // The common parent of exceptions when the type requires another type // that cannot be loaded } catch (BadImageFormatException) { } if (type != null) { break; } } } else { try { type = Type.GetType(name + ", " + assemblyName, false); } catch (TargetInvocationException e) { PUtil.LogWarning("Unable to load type {0} from assembly {1}:".F(name, assemblyName)); PUtil.LogExcWarn(e); } catch (ArgumentException e) { // A generic type is loaded with bad arguments PUtil.LogWarning("Unable to load type {0} from assembly {1}:".F(name, assemblyName)); PUtil.LogExcWarn(e); } catch (System.IO.IOException) { // The common parent of exceptions when the type requires another type that // cannot be loaded } catch (BadImageFormatException) { } } return(type); }