Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        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);
            }
        }
Esempio n. 6
0
        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);
            }
        }
Esempio n. 7
0
        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 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 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.");
     }
 }
Esempio n. 10
0
 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 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;
        }
Esempio n. 12
0
        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);
            }
        }
Esempio n. 13
0
        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);
            }
        }
Esempio n. 14
0
 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);
     }
 }
        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());
            }
        }
Esempio n. 16
0
        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);
            });
        }
Esempio n. 17
0
 /// <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();
 }
Esempio n. 18
0
 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);
         }
     }
 }
Esempio n. 19
0
        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();
                    }
                }
            };
        }
Esempio n. 20
0
 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);
         }
     }
 }
 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);
         }
     }
 }
Esempio n. 22
0
        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);
            }
        }
Esempio n. 23
0
        /// <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);
        }
        void LateUpdate()
        {
            if (TogglePOV.POVKey.IsDown())
            {
                SetPOV();
            }

            if (currentChara == null && povActive)
            {
                Restore();
                Logger.Log(LogLevel.Info, "TogglePOV force reset");
            }
            else if (povActive)
            {
                currentChara.SetNeckLook(NECK_LOOK_TYPE_VER2.ANIMATION);
                UpdateCamera();
            }
        }
                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.");
                        }
                    }
                }
Esempio n. 26
0
        public static void OpenTypeInDnSpy(ICacheEntry entry)
        {
            string GetDnspyArgs(ICacheEntry centry)
            {
                // TODO support for generic types
                switch (centry)
                {
                case MethodCacheEntry m:
                    if (m.MethodInfo.ToString().Contains(',') || m.MethodInfo.DeclaringType.FullName.Contains(','))
                    {
                        throw new Exception("Unsupported type or method with generic parameters");
                    }
                    return($"\"{m.MethodInfo.DeclaringType.Assembly.Location}\" --select M:{m.MethodInfo.DeclaringType.FullName}.{m.MethodInfo.ToString().Split(new[] { ' ' }, 2).Last()}");

                case PropertyCacheEntry p:
                    if (p.PropertyInfo.DeclaringType.FullName.Contains(','))
                    {
                        throw new Exception("Unsupported type with generic parameters");
                    }
                    return($"\"{p.PropertyInfo.DeclaringType.Assembly.Location}\" --select P:{p.PropertyInfo.DeclaringType.FullName}.{p.PropertyInfo.Name}");

                case FieldCacheEntry f:
                    if (f.FieldInfo.DeclaringType.FullName.Contains(','))
                    {
                        throw new Exception("Unsupported type with generic parameters");
                    }
                    return($"\"{f.FieldInfo.DeclaringType.Assembly.Location}\" --select F:{f.FieldInfo.DeclaringType.FullName}.{f.FieldInfo.Name}");

                default:
                    throw new Exception("Cannot open dynamically generated items");
                }
            }

            try
            {
                var refString = GetDnspyArgs(entry);
                Logger.Log(LogLevel.Info, $"[DnSpyHelper] Opening {DnSpyPath} {refString}");
                Process.Start(DnSpyPath, refString);
            }
            catch (Exception e)
            {
                Logger.Log(LogLevel.Error | LogLevel.Message, "[DnSpyHelper] " + e.Message);
            }
        }
Esempio n. 27
0
        private void CacheStaticMembers(Type type)
        {
            _inspectorScrollPos = Vector2.zero;
            _fieldCache.Clear();

            if (type == null)
            {
                return;
            }

            try
            {
                CacheStaticMembersHelper(type);
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Warning, "[Inspector] CacheFields crash: " + ex);
            }
        }
Esempio n. 28
0
 /// <summary>
 /// Method to deserialize data.
 /// </summary>
 public static KKATData GetFromFile()
 {
     if (!File.Exists("./BepInEx/KKAT/KKAT_Data.xml"))
     {
         return(new KKATData());
     }
     try
     {
         using (var stream = new FileStream("./BepInEx/KKAT/KKAT_Data.xml", FileMode.Open))
         {
             return(LZ4MessagePackSerializer.Deserialize <KKATData>(stream));
         }
     }
     catch (Exception ex)
     {
         Logger.Log(LogLevel.Error, "[KK_Archetypes] Invalid data format in KKATData - " + ex);
         return(new KKATData());
     }
 }
        public static void ChangeSpecColor(Color val)
        {
            if (currentClothesComponent)
            {
                var rendererArrs        = GetRendererArrays(currentClothesComponent);
                var applicableRenderers = GetApplicableRenderers(rendererArrs).ToList();

                foreach (var renderer in applicableRenderers)
                {
                    if (renderer.material.HasProperty(_SpecularColor))
                    {
                        renderer.material.SetColor(_SpecularColor, val);
                    }
                }
            }
            else
            {
                Logger.Log(LogLevel.Info, "currentClothesComponent == null");
            }
        }
Esempio n. 30
0
        void LoadCharas(object x)
        {
            var characters = GetSelectedCharacters();

            if (characters.Count > 0)
            {
                Logger.Log(LogLevel.Message, "Character received");

                foreach (var chara in characters)
                {
                    chara.ChangeChara(MakerBridge.MakerCardPath);
                }

                UpdateStateInfo();
            }
            else
            {
                Logger.Log(LogLevel.Message, "Select a character before replacing it");
            }
        }