internal static bool Prefix(string path, ref UnityEngine.Object __result) { if (!ModAssetBundleManager.IsKnownAsset(path)) { return(true); } __result = ModAssetBundleManager.LoadAsset(path); return(false); }
internal static bool Prefix(string name, ref Texture2D __result) { if (!ModAssetBundleManager.IsKnownAsset(name)) { return(true); } __result = ModAssetBundleManager.LoadAsset(name) as Texture2D; return(__result == null); }
private static void LoadLocalizationFromBundle(string bundleName, string assetName) { AssetBundle assetBundle = ModAssetBundleManager.GetAssetBundle(bundleName); Object asset = assetBundle.LoadAsset(assetName); if (assetName.ToLower().EndsWith("json")) { LoadJSONLocalization(asset); } else if (assetName.ToLower().EndsWith("csv")) { LoadCSVLocalization(asset); } else { Logger.LogWarning("Found localization '{0}' that could not be loaded.", assetName); } }
/*static MethodBase TargetMethod() * { * MethodInfo[] methods = typeof(UnityEngine.AssetBundle).GetMethods(); * foreach (MethodInfo m in methods) * { * if (m.Name == "LoadAsset" && !m.IsGenericMethod && m.GetParameters().Length == 2) * { * //Implementation.Log("Found it"); * return m; * } * * } * Implementation.Log("AssetBundle.LoadAsset not found for patch."); * return null; * }*/ private static bool Prefix(string name, ref UnityEngine.Object __result) { if (Implementation.LOG_ALL_ASSET_CALLS) { Implementation.Log("AssetBundle.Load: '{0}'", name); } if (ModAssetBundleManager.loadingFromExternalBundle || !ModAssetBundleManager.IsKnownAsset(name)) { //Implementation.Log("AssetBundle.Load skipping '{0}'", name); return(true); } //Implementation.Log("AssetBundle.Load loading '{0}'", name); __result = ModAssetBundleManager.LoadAsset(name); if (__result == null) { Implementation.LogWarning("AssetBundle.LoadAsset failed to load the external asset '{0}'", name); } return(false); }
internal static bool Prefix(string path, ref UnityEngine.Object __result) { if (Implementation.LOG_ALL_ASSET_CALLS && !path.ToLower().StartsWith("gear")) { Implementation.Log("Resources.Load is loading '{0}'", path); } if (!ModAssetBundleManager.IsKnownAsset(path)) { //Implementation.Log(path); return(true); } //Implementation.Log("Resources.Load is loading '{0}'", path); __result = ModAssetBundleManager.LoadAsset(path); if (__result == null) { Implementation.Log("Resources.Load failed to load the external asset"); } return(false); }
private static void LoadCSVLocalization(Object asset) { TextAsset textAsset = asset.Cast <TextAsset>(); if (textAsset is null) { Logger.LogWarning("Asset called '{0}' is not a TextAsset as expected.", asset.name); return; } //Implementation.Log("Processing asset '{0}' as csv localization.", asset.name); ByteReader byteReader = new ByteReader(textAsset); string[] languages = ModAssetBundleManager.Trim(byteReader.ReadCSV().ToArray()); while (true) { string[] values = byteReader.ReadCSV()?.ToArray(); if (values is null || languages is null || values.Length == 0 || languages.Length == 0) { break; } string locID = values[0]; Dictionary <string, string> locDict = new Dictionary <string, string>(); int maxIndex = System.Math.Min(values.Length, languages.Length); for (int j = 1; j < maxIndex; j++) { if (!string.IsNullOrEmpty(values[j]) && !string.IsNullOrEmpty(languages[j])) { locDict.Add(languages[j], values[j]); } } LoadLocalization(locID, locDict, USE_ENGLISH_AS_DEFAULT); } }