private static void OnGameBeingSaved(string path, string fileName) { var args = new GameSaveLoadEventArgs(path, fileName); foreach (var behaviour in _registeredHandlers) { try { behaviour.Key.OnGameSave(args); } catch (Exception e) { Logger.Log(LogLevel.Error, e); } } try { GameSave?.Invoke(KoikatuAPI.Instance, args); } catch (Exception e) { Logger.Log(LogLevel.Error, e); } }
private static void PrintRecursive(StreamWriter sw, GameObject obj, int d) { //Console.WriteLine(obj.name); var pad1 = new string(' ', 3 * d); var pad2 = new string(' ', 3 * (d + 1)); var pad3 = new string(' ', 3 * (d + 2)); sw.WriteLine(pad1 + obj.name + "--" + obj.GetType().FullName); foreach (Component c in obj.GetComponents <Component>()) { sw.WriteLine(pad2 + "::" + c.GetType().Name); var ct = c.GetType(); var props = ct.GetProperties(System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); foreach (var p in props) { try { var v = p.GetValue(c, null); sw.WriteLine(pad3 + "@" + p.Name + "<" + p.PropertyType.Name + "> = " + v); } catch (Exception e) { Logger.Log(LogLevel.Debug, e); } } } foreach (Transform t in obj.transform) { PrintRecursive(sw, t.gameObject, d + 1); } }
private void ApplyOverlays(ChaClothesComponent clothesCtrl) { if (CurrentOverlayTextures == null) { return; } var clothesName = clothesCtrl.name; var rendererArrs = GetRendererArrays(clothesCtrl); if (_dumpCallback != null && _dumpClothesId == clothesName) { DumpBaseTextureImpl(rendererArrs); } if (CurrentOverlayTextures.Count == 0) { return; } if (!CurrentOverlayTextures.TryGetValue(clothesName, out var overlay) || overlay == null) { return; } var applicableRenderers = GetApplicableRenderers(rendererArrs).ToList(); if (applicableRenderers.Count == 0) { Logger.Log(MakerAPI.InsideMaker ? LogLevel.Warning | LogLevel.Message : LogLevel.Debug, $"[KCOX] Removing unused overlay for {clothesName}"); Destroy(overlay.Texture); CurrentOverlayTextures.Remove(clothesName); return; } foreach (var renderer in applicableRenderers) { var mat = renderer.material; var mainTexture = (RenderTexture)mat.mainTexture; if (mainTexture == null) { return; } if (overlay.Override) { var rta = RenderTexture.active; RenderTexture.active = mainTexture; GL.Clear(false, true, Color.clear); RenderTexture.active = rta; } if (overlay.Texture != null) { KoiSkinOverlayController.ApplyOverlay(mainTexture, overlay.Texture); } } }
public static void DumpMissingTranslations() { if (!is_initialized) { throw new TranslatorException("Translator not initialized"); } foreach (KeyValuePair <string, List <string> > entry in missing) { string filePath = Path.Combine(trans_dir, string.Format("missing_{0}.txt", entry.Key)); try { using (StreamWriter writer = new StreamWriter(filePath, false, Encoding.UTF8)) { // The game internally uses \n for linebreaks so make sure the writer does the same writer.NewLine = "\n"; foreach (string missingTrans in entry.Value) { writer.WriteLine(T_ML_STARTEND); writer.WriteLine(missingTrans); writer.WriteLine(T_ML_DELIM); writer.WriteLine(T_ML_STARTEND); writer.WriteLine(); } } } catch (IOException) { Logger.Log(LogLevel.Error, string.Format("Unable to write file '{0}'", Path.GetFileName(filePath))); } } }
private static void OnObjectsBeingCopied() { var readonlyDict = GetLoadedObjects(SceneOperationKind.Import).ToReadOnlyDictionary(); foreach (var behaviour in _registeredHandlers) { try { behaviour.Key.OnObjectsCopied(readonlyDict); } catch (Exception e) { Logger.Log(LogLevel.Error, e); } } try { ObjectsCopied?.Invoke(KoikatuAPI.Instance, new ObjectsCopiedEventArgs(readonlyDict)); } catch (Exception e) { Logger.Log(LogLevel.Error, e); } }
public static string Translate(string domain, string text) { string translated = text; if (is_initialized && domain != TranslationDomain.D_DISABLED && text.Length > 0 && text.Trim().Length > 0) { if (dict.ContainsKey(domain) && dict[domain].ContainsKey(text)) { translated = dict[domain][text]; } else { Logger.Log(LogLevel.Debug, string.Format("Missing translation: `{0}`", text)); // Save the missing translation if needed if (!missing.ContainsKey(domain)) { missing.Add(domain, new List <string>() { text }); } else if (!missing[domain].Contains(text)) { missing[domain].Add(text); } } } return(translated); }
public void DisplayInspector() { if (_alignedButtonStyle == null) { _alignedButtonStyle = new GUIStyle(GUI.skin.button) { alignment = TextAnchor.MiddleLeft, wordWrap = true }; } if (Event.current.keyCode == KeyCode.Return) { _userHasHitReturn = true; } while (_inspectorStack.Count > 0 && !_inspectorStack.Peek().EntryIsValid()) { var se = _inspectorStack.Pop(); Logger.Log(LogLevel.Message, $"[Inspector] Removed invalid/removed stack object: \"{se.Name}\""); } if (_inspectorStack.Count != 0) { EditorUtilities.DrawSolidWindowBackground(_inspectorWindowRect); _inspectorWindowRect = GUILayout.Window(_windowId, _inspectorWindowRect, InspectorWindow, "Inspector"); } }
/// <summary> /// Method to retrieve a list of BoneModifiers from a selected card in the maker, without loading a character. /// </summary> public static List <BoneModifier> GetBoneModifiersFromCard() { ChaFile file = Utilities.GetSelectedCharacter(); PluginData bonedata = ExtendedSave.GetExtendedDataById(file, "KKABMPlugin.ABMData"); List <BoneModifier> modifiers = new List <BoneModifier>(); if (bonedata != null) { try { switch (bonedata.version) { // Only support for version 2 case 2: modifiers = LZ4MessagePackSerializer.Deserialize <List <BoneModifier> >((byte[])bonedata.data["boneData"]); break; default: throw new NotSupportedException($"Save version {bonedata.version} is not supported"); } } catch (Exception ex) { Logger.Log(LogLevel.Error, "[KK_Archetypes] Failed to load KKABMX extended data - " + ex); } } return(modifiers); }
private void DrawEditableValue(ICacheEntry field, object value, params GUILayoutOption[] layoutParams) { var isBeingEdited = _currentlyEditingTag == field; var text = isBeingEdited ? _currentlyEditingText : EditorUtilities.ExtractText(value); var result = GUILayout.TextField(text, layoutParams); if (!Equals(text, result) || isBeingEdited) { if (_userHasHitReturn) { _currentlyEditingTag = null; _userHasHitReturn = false; try { var converted = Convert.ChangeType(result, field.Type()); if (!Equals(converted, value)) { field.SetValue(converted); } } catch (Exception ex) { Logger.Log(LogLevel.Error, "[Inspector] Failed to set value - " + ex.Message); } } else { _currentlyEditingText = result; _currentlyEditingTag = field; } } }
private static void OnSceneBeingLoaded(SceneOperationKind operation) { var readonlyDict = GetLoadedObjects(operation).ToReadOnlyDictionary(); foreach (var behaviour in _registeredHandlers) { try { behaviour.Key.OnSceneLoad(operation, readonlyDict); } catch (Exception e) { Logger.Log(LogLevel.Error, e); } } try { SceneLoad?.Invoke(KoikatuAPI.Instance, new SceneLoadEventArgs(operation, readonlyDict)); } catch (Exception e) { Logger.Log(LogLevel.Error, e); } }
internal static void Init(bool insideStudio) { if (insideStudio) { return; } Hooks.SetupHooks(); _functionControllerContainer = new GameObject("GameCustomFunctionController Zoo"); _functionControllerContainer.transform.SetParent(Chainloader.ManagerObject.transform, false); SceneManager.sceneLoaded += (arg0, mode) => { if (arg0.name == "MyRoom" && Manager.Scene.Instance.LoadSceneName != "H") { foreach (var registeredHandler in _registeredHandlers) { try { registeredHandler.Key.OnEnterNightMenu(); } catch (Exception e) { Logger.Log(LogLevel.Error, e); } } } }; if (KoikatuAPI.EnableDebugLogging) { RegisterExtraBehaviour <TestGameFunctionController>(null); } }
private static IEnumerator OnHStart(HSceneProc proc) { yield return(null); foreach (var behaviour in _registeredHandlers) { try { behaviour.Key.OnStartH(proc, proc.flags.isFreeH); } catch (Exception e) { Logger.Log(LogLevel.Error, e); } } try { StartH?.Invoke(KoikatuAPI.Instance, EventArgs.Empty); } catch (Exception e) { Logger.Log(LogLevel.Error, e); } }
public static IEnumerable <ReadonlyCacheEntry> GetRootGoScanner() { Logger.Log(LogLevel.Debug, "[CheatTools] Looking for Root Game Objects..."); foreach (GameObject go in Resources.FindObjectsOfTypeAll <GameObject>().Where(x => x.transform == x.transform.root)) { yield return(new ReadonlyCacheEntry($"GameObject({go.name})", go)); } }
public static void IterateCoordinatePrefixesPrefix(ref IEnumerable <ResolveInfo> extInfo, ChaFileCoordinate coordinate) { try { extInfo = Migrate.MigrateGUID(extInfo); } catch { Logger.Log(LogLevel.Error | LogLevel.Message, $"GUID migration failed. Please update KK_GUIDMigration and/or BepisPlugins."); } }
public static void IterateCardPrefixesPrefix(ref IEnumerable <ResolveInfo> extInfo, ChaFile file) { try { extInfo = Migrate.MigrateGUID(extInfo, file.parameter.fullname.Trim()); } catch { Logger.Log(LogLevel.Error | LogLevel.Message, $"GUID migration failed. Please update KK_GUIDMigration and/or BepisPlugins."); } }
public static void ChangeCustomClothesPostHook(ChaControl __instance, ref bool main, ref int kind) { var clothesCtrl = GetCustomClothesComponent(__instance, main, kind); if (!clothesCtrl) { Logger.Log(LogLevel.Info, "No clothes component found"); return; } currentClothesComponent = clothesCtrl; }
public static IEnumerable <ReadonlyCacheEntry> GetTransformScanner() { Logger.Log(LogLevel.Debug, "[CheatTools] Looking for Transforms..."); var trt = typeof(Transform); var types = GetAllComponentTypes().Where(x => trt.IsAssignableFrom(x)); foreach (var component in ScanComponentTypes(types, false)) { yield return(component); } }
public static void InstallHooks() { try { var harmony = HarmonyInstance.Create("meidodev.io.translator"); harmony.PatchAll(typeof(Hooks)); } catch (System.Exception e) { Logger.Log(BepInEx.Logging.LogLevel.Error, e.Message); } }
public static void InstallHooks() { try { var harmony = HarmonyInstance.Create("com.bepis.bepinex.dynamictranslationloader"); harmony.PatchAll(typeof(ImageHooks)); } catch (System.Exception e) { Logger.Log(LogLevel.Error, e); } }
public static IEnumerable <ReadonlyCacheEntry> GetMonoBehaviourScanner() { Logger.Log(LogLevel.Debug, "[CheatTools] Looking for MonoBehaviours..."); var mbt = typeof(MonoBehaviour); var types = GetAllComponentTypes().Where(x => mbt.IsAssignableFrom(x)); foreach (var component in ScanComponentTypes(types, true)) { yield return(component); } }
internal static void DisplaySubtitle(LoadVoice voice, string text, string speaker = "") { if (KK_Subtitles.showUntranslated.Value == false) { foreach (var x in text.ToList()) { if (JPChars.Contains(x)) { return; } } } Font fontFace = (Font)Resources.GetBuiltinResource(typeof(Font), $"{KK_Subtitles.fontName.Value}.ttf"); int fsize = KK_Subtitles.fontSize.Value; fsize = (int)(fsize < 0 ? (fsize * Screen.height / -100.0) : fsize); GameObject subtitle = new GameObject(voice.assetName); subtitle.transform.SetParent(Pane.transform); var rect = subtitle.GetComponent <RectTransform>() ?? subtitle.AddComponent <RectTransform>(); rect.pivot = new Vector2(0.5f, 0); rect.sizeDelta = new Vector2(Screen.width * 0.990f, fsize + (fsize * 0.05f)); var subtitleText = subtitle.GetComponent <Text>() ?? subtitle.AddComponent <Text>(); subtitleText.font = fontFace; subtitleText.fontSize = fsize; subtitleText.fontStyle = fontFace.dynamic ? KK_Subtitles.fontStyle.Value : FontStyle.Normal; subtitleText.alignment = KK_Subtitles.textAlign.Value; subtitleText.horizontalOverflow = HorizontalWrapMode.Wrap; subtitleText.verticalOverflow = VerticalWrapMode.Overflow; subtitleText.color = KK_Subtitles.textColor.Value; var subOutline = subtitle.GetComponent <Outline>() ?? subtitle.AddComponent <Outline>(); subOutline.effectColor = KK_Subtitles.outlineColor.Value; subOutline.effectDistance = new Vector2(KK_Subtitles.outlineThickness.Value, KK_Subtitles.outlineThickness.Value); subtitleText.text = speaker.IsNullOrEmpty() ? text : $"{speaker}:{text}"; Logger.Log(LogLevel.Debug, $"KK_Subtitles:{text}"); voice.OnDestroyAsObservable().Subscribe(delegate(Unit _) { subtitle.transform.SetParent(null); Object.Destroy(subtitle); }); }
protected override void OnReload(GameMode currentGameMode) { if (!KoiClothesOverlayGui.MakerLoadFromCharas) { return; } var anyPrevious = _allOverlayTextures != null && _allOverlayTextures.Any(); if (anyPrevious) { foreach (var textures in _allOverlayTextures) { foreach (var texture in textures.Value) { Destroy(texture.Value.Texture); } } _allOverlayTextures = null; } var pd = GetExtendedData(); if (pd != null && pd.data.TryGetValue(OverlayDataKey, out var overlayData)) { if (overlayData is byte[] overlayBytes) { try { _allOverlayTextures = MessagePackSerializer.Deserialize < Dictionary <ChaFileDefine.CoordinateType, Dictionary <string, ClothesTexData> > >( overlayBytes); } catch (Exception ex) { var logLevel = currentGameMode == GameMode.Maker ? LogLevel.Message | LogLevel.Warning : LogLevel.Warning; Logger.Log(logLevel, "[KCOX] WARNING: Failed to load embedded overlay data for " + (ChaFileControl?.charaFileName ?? "?")); Logger.Log(LogLevel.Debug, ex); } } } if (_allOverlayTextures == null) { _allOverlayTextures = new Dictionary <ChaFileDefine.CoordinateType, Dictionary <string, ClothesTexData> >(); } if (anyPrevious || _allOverlayTextures.Any()) { StartCoroutine(RefreshAllTexturesCo()); } }
/// <summary> /// Method to serialize data. /// </summary> public void SaveToFile() { if (!Directory.Exists("./BepInEx/KKAT/")) { Directory.CreateDirectory("./BepInEx/KKAT/"); } using (var stream = new FileStream("./BepInEx/KKAT/KKAT_Data.xml", FileMode.Create)) { LZ4MessagePackSerializer.Serialize <KKATData>(stream, this); } Logger.Log(LogLevel.Message, "Successfully saved Archetype Favorite Data!"); Utilities.PlaySound(); }
public static void GetReverseParentPrefix(ChaAccessoryDefine.AccessoryParentKey key, ref ChaAccessoryDefine.AccessoryParentKey __result) { if (__result == ChaAccessoryDefine.AccessoryParentKey.none) { try { __result = (ChaAccessoryDefine.AccessoryParentKey)Enum.Parse(EnumAccesoryParentKeyType, InterfaceEntries.FindReverseBone(key.ToString())); } catch (Exception e) { Logger.Log(LogLevel.Error, e); } } }
public static void LoadImageTranslations(string dirTranslation) { var diTl = new DirectoryInfo(Path.Combine(dirTranslation, "Images")); TL_DIR_ROOT = $"{diTl.FullName}/{Application.productName}"; TL_DIR_SCENE = $"{TL_DIR_ROOT}/Scenes"; var di = new DirectoryInfo(TL_DIR_SCENE); if (!di.Exists) { di.Create(); } foreach (var t in new DirectoryInfo(TL_DIR_ROOT).GetFiles("*.txt")) { var sceneName = Path.GetFileNameWithoutExtension(t.Name); TextureLoadTargets[sceneName] = new Dictionary <string, byte[]>(); foreach (var tl in File.ReadAllLines(t.FullName)) { var tp = tl.Split('='); if (tp.Length != 2) { Logger.Log(LogLevel.Warning, "Invalid entry in " + t.Name + " - " + tl); continue; } var path = $"{TL_DIR_SCENE}/{tp[1]}"; if (!File.Exists(path)) { Logger.Log(LogLevel.Warning, "Missing TL image: " + path); continue; } TextureLoadTargets[sceneName][tp[0]] = File.ReadAllBytes(path); } } GlobalTextureTargetExists = TextureLoadTargets.ContainsKey(GlobalTextureTargetName); SceneManager.sceneUnloaded += s => { if (DynamicTranslator.IsDumpingEnabled.Value) { var sn = DynamicTranslator.DumpingAllToGlobal.Value ? GlobalTextureTargetName : s.name; if (SwTextureNameDump.TryGetValue(sn, out var sw)) { sw.Flush(); } } }; }
private static void OnPeriodChange(Cycle.Type period) { foreach (var behaviour in _registeredHandlers) { try { behaviour.Key.OnPeriodChange(period); } catch (Exception e) { Logger.Log(LogLevel.Error, e); } } }
private static void OnDayChange(Cycle.Week day) { foreach (var behaviour in _registeredHandlers) { try { behaviour.Key.OnDayChange(day); } catch (Exception e) { Logger.Log(LogLevel.Error, e); } } }
public static IEnumerable <ReadonlyCacheEntry> GetComponentScanner() { Logger.Log(LogLevel.Debug, "[CheatTools] Looking for Components..."); var mbt = typeof(MonoBehaviour); var trt = typeof(Transform); var allComps = GetAllComponentTypes().ToList(); var types = allComps.Where(x => !mbt.IsAssignableFrom(x) && !trt.IsAssignableFrom(x)); foreach (var component in ScanComponentTypes(types, true)) { yield return(component); } }
/// <summary> /// Add a new custom category to the Anim > CurrentState tab in the studio top-left menu. /// Can use this at any point. /// </summary> public static void CreateCurrentStateCategory(CurrentStateCategory category) { if (!InsideStudio) { Logger.Log(LogLevel.Warning, "[StudioAPI] Tried to run CreateCurrentStateCategory outside of studio!"); return; } if (_studioLoaded) { CreateCategory(category); } _customCurrentStateCategories.Add(category); }
private static IEnumerator HandleUVCorrupionsCo(SkinnedMeshRenderer dst, Vector2[] uvCopy) { // Wait for next frame to let the graphics logic run. Issue seems to happen between frames. yield return(null); // Check if UVs got corrupted after moving the mesh, most common fail point if (!dst.sharedMesh.uv.SequenceEqual(uvCopy)) { Logger.Log(LogLevel.Warning, $"UVs got corrupted when changing uncensor mesh {dst.sharedMesh.name}, attempting to fix"); dst.sharedMesh.uv = uvCopy; yield return(null); if (!dst.sharedMesh.uv.SequenceEqual(uvCopy)) { Logger.Log(LogLevel.Error, "Failed to fix UVs, body textures might be displayed corrupted. Consider updating your GPU drivers."); } } }