コード例 #1
0
        void LoadCharaInMaker(string path)
        {
            //confirmpanel.gameObject.SetActive(false);
            //optionspanel.gameObject.SetActive(false);
            //if(autoClose) UISystem.gameObject.SetActive(false);

            bool face = true, body = true, hair = true;
            bool parameter = true, coordinate = true;

            ChaControl chaCtrl = CustomBase.Instance.chaCtrl;

            chaCtrl.chaFile.LoadFileLimited(path, chaCtrl.sex, face, body, hair, parameter, coordinate);
            chaCtrl.ChangeCoordinateType(true);
            chaCtrl.Reload(!coordinate, !face && !coordinate, !hair, !body);
            CustomBase.Instance.updateCustomUI = true;
            CustomHistory.Instance.Add5(chaCtrl, chaCtrl.Reload, !coordinate, !face && !coordinate, !hair, !body);
        }
コード例 #2
0
        private void Start()
        {
            CharacterApi.RegisterExtraBehaviour <MaterialRouterController>(GUID);

            HooksInstance = Harmony.CreateAndPatchAll(typeof(Hooks));

            BepInEx.Bootstrap.Chainloader.PluginInfos.TryGetValue("com.deathweasel.bepinex.materialeditor", out PluginInfo PluginInfo);
            Type MaterialEditorCharaController = PluginInfo.Instance.GetType().Assembly.GetType("KK_Plugins.MaterialEditor.MaterialEditorCharaController");

            HooksInstance.Patch(MaterialEditorCharaController.GetMethod("OnReload", AccessTools.all, null, new[] { typeof(GameMode), typeof(bool) }, null), prefix: new HarmonyMethod(typeof(Hooks), nameof(Hooks.MaterialEditorCharaController_OnReload_Prefix)));
            HooksInstance.Patch(MaterialEditorCharaController.GetMethod("OnCoordinateBeingLoaded", AccessTools.all, null, new[] { typeof(ChaFileCoordinate), typeof(bool) }, null), prefix: new HarmonyMethod(typeof(Hooks), nameof(Hooks.MaterialEditorCharaController_OnCoordinateBeingLoaded_Prefix)));
            HooksInstance.Patch(MaterialEditorCharaController.GetMethod("CorrectTongue", AccessTools.all, null, new Type[0], null), prefix: new HarmonyMethod(typeof(Hooks), nameof(Hooks.MaterialEditorCharaController_CorrectTongue_Prefix)));
            Type MaterialEditorMaterialAPI = PluginInfo.Instance.GetType().Assembly.GetType("MaterialEditorAPI.MaterialAPI");

            if (MaterialEditorMaterialAPI.GetMethods().Single(x => x.Name == "SetTexture").GetParameters().ElementAtOrDefault(3)?.ParameterType == typeof(Texture))
            {
                HooksInstance.Patch(MaterialEditorMaterialAPI.GetMethod("SetTexture", AccessTools.all, null, new[] { typeof(GameObject), typeof(string), typeof(string), typeof(Texture) }, null), prefix: new HarmonyMethod(typeof(Hooks), nameof(Hooks.MaterialAPI_SetTexture_Prefix)));
            }
            else
            {
                HooksInstance.Patch(MaterialEditorMaterialAPI.GetMethod("SetTexture", AccessTools.all, null, new[] { typeof(GameObject), typeof(string), typeof(string), typeof(Texture2D) }, null), prefix: new HarmonyMethod(typeof(Hooks), nameof(Hooks.MaterialAPI_SetTexture_Prefix)));
            }

            MakerAPI.MakerBaseLoaded += (object sender, RegisterCustomControlsEvent ev) =>
            {
                HooksMakerInstance = Harmony.CreateAndPatchAll(typeof(HooksMaker));
            };

            MakerAPI.MakerFinishedLoading += (object sender, EventArgs ev) =>
            {
                btmGetTemplate.Visible.OnNext(false);
                btmImportSetting.Visible.OnNext(false);
                btmRemoveSetting.Visible.OnNext(false);
            };

            AccessoriesApi.SelectedMakerAccSlotChanged += (object sender, AccessorySlotEventArgs ev) =>
            {
                InitCurrentSlot();
            };

            MakerAPI.MakerExiting += (object sender, EventArgs ev) =>
            {
                HooksMakerInstance.UnpatchAll(HooksMakerInstance.Id);
                HooksMakerInstance = null;
            };

            AccessoriesApi.AccessoryTransferred += (object sender, AccessoryTransferEventArgs ev) =>
            {
                MaterialRouterController pluginCtrl = GetController(MakerAPI.GetCharacterControl());
                pluginCtrl.AccessoryTransferEvent(ev);
            };

            AccessoriesApi.AccessoriesCopied += (object sender, AccessoryCopyEventArgs ev) =>
            {
                MaterialRouterController pluginCtrl = GetController(MakerAPI.GetCharacterControl());
                pluginCtrl.AccessoryCopyEvent(ev);
            };

            MakerAPI.RegisterCustomSubCategories += (object sender, RegisterSubCategoriesEvent ev) =>
            {
                ChaControl chaCtrl = MakerAPI.GetCharacterControl();
                MaterialRouterController pluginCtrl = GetController(chaCtrl);

                MakerCategory category = new MakerCategory("05_ParameterTop", "tglMaterialRouter", MakerConstants.Parameter.Attribute.Position + 1, "Router");
                ev.AddSubCategory(category);

                ev.AddControl(new MakerText("BodyTrigger", category, this));

                ev.AddControl(new MakerButton("Export", category, this)).OnClick.AddListener(delegate { pluginCtrl.ExportBodyTrigger(); });
                ev.AddControl(new MakerButton("Import", category, this)).OnClick.AddListener(delegate { pluginCtrl.ImportBodyTrigger(); });
                ev.AddControl(new MakerButton("Reset", category, this)).OnClick.AddListener(delegate { pluginCtrl.ResetBodyTrigger(); });

                ev.AddControl(new MakerSeparator(category, this));

                ev.AddControl(new MakerText("OutfitTriggers", category, this));

                ev.AddControl(new MakerButton("Export", category, this)).OnClick.AddListener(delegate { pluginCtrl.ExportOutfitTrigger(); });
                ev.AddControl(new MakerButton("Import", category, this)).OnClick.AddListener(delegate { pluginCtrl.ImportOutfitTrigger(); });
                ev.AddControl(new MakerButton("Reset", category, this)).OnClick.AddListener(delegate { pluginCtrl.ResetOutfitTrigger(); });

                ev.AddControl(new MakerSeparator(category, this));

                ev.AddControl(new MakerText("Config", category, this));

                tglSkipCloned = ev.AddControl(new MakerToggle(category, "Get Template Skip Cloned", CfgSkipCloned.Value, this));
                tglSkipCloned.ValueChanged.Subscribe(value => CfgSkipCloned.Value = value);

                ev.AddControl(new MakerSeparator(category, this));

                ev.AddControl(new MakerText("Tools", category, this));

                ev.AddControl(new MakerButton("Reload", category, Instance)).OnClick.AddListener(delegate
                {
                    string CardPath = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Paths.ExecutablePath) + "_MaterialRouter.png");
                    chaCtrl.chaFile.SaveCharaFile(CardPath, byte.MaxValue, false);

                    chaCtrl.chaFile.LoadFileLimited(CardPath);
                    if (chaCtrl.chaFile.GetLastErrorCode() != 0)
                    {
                        throw new Exception("LoadFileLimited failed");
                    }
                    chaCtrl.ChangeCoordinateType(true);
                    chaCtrl.Reload();
                    CustomBase.Instance.updateCustomUI = true;
                });

                ev.AddControl(new MakerButton("Info", category, Instance)).OnClick.AddListener(delegate
                {
                    Logger.LogInfo($"[BodyTrigger][{pluginCtrl?.BodyTrigger?.Count}]");
                    for (int i = 0; i < chaCtrl.chaFile.coordinate.Length; i++)
                    {
                        Logger.LogInfo($"[OutfitTriggers][{i}][{pluginCtrl?.OutfitTriggers?[i].Count}]");
                    }
                });

                ev.AddControl(new MakerButton("Head Get Template", MakerConstants.Face.All, this)).OnClick.AddListener(() => PrintRendererInfo(chaCtrl, chaCtrl.objHead, true));
                ev.AddControl(new MakerButton("Body Get Template", MakerConstants.Face.All, this)).OnClick.AddListener(() => PrintRendererInfo(chaCtrl, chaCtrl.objBody, true));

                const string labelConsolePrint    = "Console Output";
                const string labelGenerateSetting = "Generate Setting";
                const string labelRemoveSetting   = "Remove Setting";

                ev.AddControl(new MakerButton(labelConsolePrint, MakerConstants.Clothes.Top, this)).OnClick.AddListener(() => PrintRendererInfo(chaCtrl, chaCtrl.objClothes[0]));
                ev.AddControl(new MakerButton(labelConsolePrint, MakerConstants.Clothes.Bottom, this)).OnClick.AddListener(() => PrintRendererInfo(chaCtrl, chaCtrl.objClothes[1]));
                ev.AddControl(new MakerButton(labelConsolePrint, MakerConstants.Clothes.Bra, this)).OnClick.AddListener(() => PrintRendererInfo(chaCtrl, chaCtrl.objClothes[2]));
                ev.AddControl(new MakerButton(labelConsolePrint, MakerConstants.Clothes.Shorts, this)).OnClick.AddListener(() => PrintRendererInfo(chaCtrl, chaCtrl.objClothes[3]));
                ev.AddControl(new MakerButton(labelConsolePrint, MakerConstants.Clothes.Gloves, this)).OnClick.AddListener(() => PrintRendererInfo(chaCtrl, chaCtrl.objClothes[4]));
                ev.AddControl(new MakerButton(labelConsolePrint, MakerConstants.Clothes.Panst, this)).OnClick.AddListener(() => PrintRendererInfo(chaCtrl, chaCtrl.objClothes[5]));
                ev.AddControl(new MakerButton(labelConsolePrint, MakerConstants.Clothes.Socks, this)).OnClick.AddListener(() => PrintRendererInfo(chaCtrl, chaCtrl.objClothes[6]));
                ev.AddControl(new MakerButton(labelConsolePrint, MakerConstants.Clothes.InnerShoes, this)).OnClick.AddListener(() => PrintRendererInfo(chaCtrl, chaCtrl.objClothes[7]));
                ev.AddControl(new MakerButton(labelConsolePrint, MakerConstants.Clothes.OuterShoes, this)).OnClick.AddListener(() => PrintRendererInfo(chaCtrl, chaCtrl.objClothes[8]));

                btmGetTemplate = MakerAPI.AddAccessoryWindowControl(new MakerButton(labelConsolePrint, null, this));
                btmGetTemplate.OnClick.AddListener(() => PrintRendererInfo(chaCtrl, chaCtrl.GetAccessoryObject(AccessoriesApi.SelectedMakerAccSlot)));
                btmImportSetting = MakerAPI.AddAccessoryWindowControl(new MakerButton(labelGenerateSetting, null, this));
                btmImportSetting.OnClick.AddListener(() => pluginCtrl.ImportFromRendererInfo(AccessoriesApi.SelectedMakerAccSlot));
                btmRemoveSetting = MakerAPI.AddAccessoryWindowControl(new MakerButton(labelRemoveSetting, null, this));
                btmRemoveSetting.OnClick.AddListener(() => pluginCtrl.RemoveAccSlotInfo(AccessoriesApi.SelectedMakerAccSlot));

                ev.AddControl(new MakerButton(labelConsolePrint, MakerConstants.Hair.Back, this)).OnClick.AddListener(() => PrintRendererInfo(chaCtrl, chaCtrl.objHair[0], true));
                ev.AddControl(new MakerButton(labelConsolePrint, MakerConstants.Hair.Front, this)).OnClick.AddListener(() => PrintRendererInfo(chaCtrl, chaCtrl.objHair[1], true));
                ev.AddControl(new MakerButton(labelConsolePrint, MakerConstants.Hair.Side, this)).OnClick.AddListener(() => PrintRendererInfo(chaCtrl, chaCtrl.objHair[2], true));
                ev.AddControl(new MakerButton(labelConsolePrint, MakerConstants.Hair.Extension, this)).OnClick.AddListener(() => PrintRendererInfo(chaCtrl, chaCtrl.objHair[3], true));
            };
        }