static AssetBundle MM_Detour(string path, uint crc, ulong offset)
        {
            AssetBundle result;

            var parameters = new AssetBundleLoadingParameters(null, path, crc, offset, AssetBundleLoadType.LoadFromFile);
            var context    = ResourceRedirection.Hook_AssetBundleLoading_Prefix(parameters, out result);

            var p = context.Parameters;

            if (!context.SkipOriginalCall)
            {
                result = _original(p.Path, p.Crc, p.Offset);
            }

            if (!context.SkipAllPostfixes)
            {
                ResourceRedirection.Hook_AssetBundleLoaded_Postfix(parameters, ref result);
            }

            if (result != null && p.Path != null) // should only be null if loaded through non-hooked methods
            {
                var ext = result.GetOrCreateExtensionData <AssetBundleExtensionData>();
                ext.Path = p.Path;
            }

            return(result);
        }
Ejemplo n.º 2
0
        private void Awake()
        {
            Instance = this;
            Logger   = base.Logger;
            Directory.CreateDirectory(ExportPath);

            UIScale = Config.Bind("Config", "UI Scale", 1.75f, new ConfigDescription("Controls the size of the window.", new AcceptableValueRange <float>(1f, 3f), new ConfigurationManagerAttributes {
                Order = 5
            }));
            UIWidth = Config.Bind("Config", "UI Width", 0.3f, new ConfigDescription("Controls the size of the window.", new AcceptableValueRange <float>(0f, 1f), new ConfigurationManagerAttributes {
                Order = 4, ShowRangeAsPercent = false
            }));
            UIHeight = Config.Bind("Config", "UI Height", 0.3f, new ConfigDescription("Controls the size of the window.", new AcceptableValueRange <float>(0f, 1f), new ConfigurationManagerAttributes {
                Order = 3, ShowRangeAsPercent = false
            }));
            WatchTexChanges = Config.Bind("Config", "Watch File Changes", true, new ConfigDescription("Watch for file changes and reload textures on change. Can be toggled in the UI.", null, new ConfigurationManagerAttributes {
                Order = 2
            }));
            ShaderOptimization = Config.Bind("Config", "Shader Optimization", true, new ConfigDescription("Replaces every loaded shader with the MaterialEditor copy of the shader. Reduces the number of copies of shaders loaded which reduces RAM usage and improves performance.", null, new ConfigurationManagerAttributes {
                Order = 1
            }));
            ExportBakedMesh = Config.Bind("Config", "Export Baked Mesh", false, new ConfigDescription("When enabled, skinned meshes will be exported in their current state with all customization applied as well as in the current pose.", null, new ConfigurationManagerAttributes {
                Order = 1
            }));

            UIScale.SettingChanged            += MaterialEditorUI.UISettingChanged;
            UIWidth.SettingChanged            += MaterialEditorUI.UISettingChanged;
            UIHeight.SettingChanged           += MaterialEditorUI.UISettingChanged;
            WatchTexChanges.SettingChanged    += WatchTexChanges_SettingChanged;
            ShaderOptimization.SettingChanged += ShaderOptimization_SettingChanged;

            ResourceRedirection.RegisterAssetLoadedHook(HookBehaviour.OneCallbackPerResourceLoaded, AssetLoadedHook);
            LoadXML();
        }
 static void MM_Detour(AssetBundleCreateRequest self, bool set)
 {
     if (!ResourceRedirection.TryGetAssetBundle(self, out var result))
     {
         _original(self, set);
     }
 }
Ejemplo n.º 4
0
        internal void Awake()
        {
            Logger = base.Logger;

            Hooks.InstallHooks();
            UniversalAutoResolver.Hooks.InstallHooks();
            Lists.Hooks.InstallHooks();

            ResourceRedirection.EnableSyncOverAsyncAssetLoads();
            ResourceRedirection.EnableRedirectMissingAssetBundlesToEmptyAssetBundle(-1000);
            ResourceRedirection.RegisterAsyncAndSyncAssetLoadingHook(RedirectHook);
            ResourceRedirection.RegisterAssetBundleLoadingHook(AssetBundleLoadingHook);

            MissingModWarning       = Config.AddSetting("Settings", "Show missing mod warnings", true, new ConfigDescription("Whether missing mod warnings will be displayed on screen. Messages will still be written to the log."));
            DebugLogging            = Config.AddSetting("Settings", "Debug logging", false, new ConfigDescription("Enable additional logging useful for debugging issues with Sideloader and sideloader mods.\nWarning: Will increase load and save times noticeably and will result in very large log sizes."));
            DebugResolveInfoLogging = Config.AddSetting("Settings", "Debug resolve info logging", false, new ConfigDescription("Enable verbose logging for debugging issues with Sideloader and sideloader mods.\nWarning: Will increase game start up time and will result in very large log sizes."));
            ModLoadingLogging       = Config.AddSetting("Settings", "Mod loading logging", true, new ConfigDescription("Enable verbose logging when loading mods.", tags: "Advanced"));
            KeepMissingAccessories  = Config.AddSetting("Settings", "Keep missing accessories", false, new ConfigDescription("Missing accessories will be replaced by a default item with color and position information intact when loaded in the character maker."));
            MigrationEnabled        = Config.AddSetting("Settings", "Migration enabled", true, new ConfigDescription("Attempt to change the GUID and or ID of mods based on the data configured in the manifest.xml."));
            AdditionalModsDirectory = Config.AddSetting("General", "Additional mods directory", FindKoiZipmodDir(), new ConfigDescription("Additional directory to load zipmods from."));

            if (!Directory.Exists(ModsDirectory))
            {
                Logger.LogWarning("Could not find the mods directory: " + ModsDirectory);
            }

            if (!AdditionalModsDirectory.Value.IsNullOrWhiteSpace() && !Directory.Exists(AdditionalModsDirectory.Value))
            {
                Logger.LogWarning("Could not find the additional mods directory specified in config: " + AdditionalModsDirectory.Value);
            }

            LoadModsFromDirectories(ModsDirectory, AdditionalModsDirectory.Value);
        }
Ejemplo n.º 5
0
 void Awake()
 {
     ResourceRedirection.RegisterAssetLoadedHook(
         behaviour: HookBehaviour.OneCallbackPerResourceLoaded,
         priority: 0,
         action: AssetLoaded);
 }
 public override void Initialize(IEnumerable <Mod> mods)
 {
     base.Initialize(mods);
     // Ensure materials are handled before textures
     ResourceRedirection.RegisterAssetLoadedHook(HookBehaviour.OneCallbackPerResourceLoaded, 100,
                                                 PatchLoadedAsset);
 }
Ejemplo n.º 7
0
 public override void Initialize(IEnumerable <Mod> mods)
 {
     base.Initialize(mods);
     ResourceRedirection.RegisterAssetLoadedHook(HookBehaviour.OneCallbackPerResourceLoaded, PatchLoadedAsset);
     ResourceRedirection.RegisterResourceLoadedHook(HookBehaviour.OneCallbackPerResourceLoaded,
                                                    PatchLoadedResource);
 }
Ejemplo n.º 8
0
        static UnityEngine.Object[] MM_Detour(AssetBundleRequest self)
        {
            if (ResourceRedirection.TryGetAssetBundleLoadInfo(self, out var info))
            {
                UnityEngine.Object[] result;

                if (info.ResolveType == AsyncAssetLoadingResolve.ThroughAssets)
                {
                    result = info.Assets;
                }
                else
                {
                    result = _original(self);
                }

                if (!info.SkipAllPostfixes)
                {
                    ResourceRedirection.Hook_AssetLoaded_Postfix(info.Parameters, info.Bundle, ref result);
                }

                return(result);
            }
            else
            {
                return(_original(self));
            }
        }
Ejemplo n.º 9
0
        static AssetBundleRequest MM_Detour(AssetBundle self, string name, Type type)
        {
            AssetBundleRequest result = null;

            if (name == string.Empty)
            {
                var parameters = new AssetLoadingParameters(null, type, AssetLoadType.LoadByType);
                var context    = ResourceRedirection.Hook_AsyncAssetLoading_Prefix(parameters, self, ref result);

                var p = context.Parameters;
                if (!context.SkipOriginalCall)
                {
                    result = _original(self, name, p.Type);
                }

                ResourceRedirection.Hook_AssetLoading_Postfix(context, result);
            }
            else
            {
                var parameters = new AssetLoadingParameters(name, type, AssetLoadType.LoadNamedWithSubAssets);
                var context    = ResourceRedirection.Hook_AsyncAssetLoading_Prefix(parameters, self, ref result);

                var p = context.Parameters;
                if (!context.SkipOriginalCall)
                {
                    result = _original(self, p.Name, p.Type);
                }

                ResourceRedirection.Hook_AssetLoading_Postfix(context, result);
            }

            return(result);
        }
Ejemplo n.º 10
0
        static AssetBundle MM_Detour(Stream stream, uint crc, uint managedReadBufferSize)
        {
            AssetBundle result;

            var parameters = new AssetBundleLoadingParameters(null, null, crc, 0, stream, managedReadBufferSize, AssetBundleLoadType.LoadFromMemory);
            var context    = ResourceRedirection.Hook_AssetBundleLoading_Prefix(parameters, out result);

            var p = context.Parameters;

            if (!context.SkipOriginalCall)
            {
                result = _original(p.Stream, p.Crc, p.ManagedReadBufferSize);
            }

            if (!context.SkipAllPostfixes)
            {
                ResourceRedirection.Hook_AssetBundleLoaded_Postfix(parameters, ref result);
            }

            if (result != null && p.Path != null) // should only be null if loaded through non-hooked methods
            {
                var ext = result.GetOrCreateExtensionData <AssetBundleExtensionData>();
                ext.Path = p.Path;
            }

            return(result);
        }
        private void Awake()
        {
            textureStorePath = Config.Bind("Paths", "TexturesStore", "GunSkins", "Path where textures are stored.");
            textureStorePath.SettingChanged += (sender, args) => InitWatcher();
            InitWatcher();

            ResourceRedirection.RegisterAssetLoadedHook(HookBehaviour.OneCallbackPerResourceLoaded, ReplaceTextures);
        }
Ejemplo n.º 12
0
        private void Awake()
        {
            ZipConstants.DefaultCodePage = Encoding.UTF8.CodePage;
            Logger = base.Logger;
            ResourceRedirection.EnableSyncOverAsyncAssetLoads();

            LoadMods();
        }
Ejemplo n.º 13
0
            void Awake()
            {
                ResourceRedirection.EnableSyncOverAsyncAssetLoads();

                ResourceRedirection.RegisterAsyncAndSyncAssetBundleLoadingHook(
                    priority: 1000,
                    action: AssetBundleLoading);
            }
Ejemplo n.º 14
0
        static UnityEngine.Object MM_Detour(string path, Type systemTypeInstance)
        {
            var result = _original(path, systemTypeInstance);

            ResourceRedirection.Hook_ResourceLoaded_Postfix(path, systemTypeInstance, ResourceLoadType.LoadNamedBuiltIn, ref result);

            return(result);
        }
Ejemplo n.º 15
0
 public void Initialize(IEnumerable <Mod> mods)
 {
     foreach (var mod in mods)
     {
         RegisterPrefabReplacements(mod);
     }
     ResourceRedirection.RegisterAsyncAndSyncAssetLoadingHook(500, ReplacePrefab);
 }
Ejemplo n.º 16
0
        private void Awake()
        {
            Log.SetLogSource(Logger);
            GatherData();

            HarmonyExtensions.CreateAndPatchAll(typeof(Loader));
            ResourceRedirection.RegisterAsyncAndSyncAssetBundleLoadingHook(0, AssetBundleLoadingHook);
            //ResourceRedirection.RegisterResourceLoadedHook(HookBehaviour.OneCallbackPerResourceLoaded, ResourceLoadedHook);
        }
Ejemplo n.º 17
0
        internal void Main()
        {
            Logger = base.Logger;
            Directory.CreateDirectory(ExportPath);

            MakerAPI.MakerExiting += (s, e) => UI.Visible = false;
            CharacterApi.RegisterExtraBehaviour <MaterialEditorCharaController>(GUID);
            AccessoriesApi.SelectedMakerAccSlotChanged += AccessoriesApi_SelectedMakerAccSlotChanged;
            AccessoriesApi.AccessoryKindChanged        += AccessoriesApi_AccessoryKindChanged;
            AccessoriesApi.AccessoryTransferred        += AccessoriesApi_AccessoryTransferred;
#if KK
            AccessoriesApi.AccessoriesCopied += AccessoriesApi_AccessoriesCopied;
#endif

            UIScale = Config.Bind("Config", "UI Scale", 1.75f, new ConfigDescription("Controls the size of the window.", new AcceptableValueRange <float>(1f, 3f), new ConfigurationManagerAttributes {
                Order = 5
            }));
            UIWidth = Config.Bind("Config", "UI Width", 0.3f, new ConfigDescription("Controls the size of the window.", new AcceptableValueRange <float>(0f, 1f), new ConfigurationManagerAttributes {
                Order = 4, ShowRangeAsPercent = false
            }));
            UIHeight = Config.Bind("Config", "UI Height", 0.3f, new ConfigDescription("Controls the size of the window.", new AcceptableValueRange <float>(0f, 1f), new ConfigurationManagerAttributes {
                Order = 3, ShowRangeAsPercent = false
            }));
            WatchTexChanges = Config.Bind("Config", "Watch File Changes", true, new ConfigDescription("Watch for file changes and reload textures on change. Can be toggled in the UI.", null, new ConfigurationManagerAttributes {
                Order = 2
            }));
            ShaderOptimization = Config.Bind("Config", "Shader Optimization", true, new ConfigDescription("Replaces every loaded shader with the MaterialEditor copy of the shader. Reduces the number of copies of shaders loaded which reduces RAM usage and improves performance.", null, new ConfigurationManagerAttributes {
                Order = 1
            }));
            WatchTexChanges.SettingChanged += WatchTexChanges_SettingChanged;

            var harmony = Harmony.CreateAndPatchAll(typeof(Hooks));

#if KK || EC
            //Hooks for transfering accessories (MoreAccessories compatibility)
            foreach (var method in typeof(ChaCustom.CvsAccessoryChange).GetMethods(AccessTools.all).Where(x => x.Name.Contains("<Start>m__4")))
            {
                harmony.Patch(method, new HarmonyMethod(typeof(Hooks).GetMethod(nameof(Hooks.AccessoryTransferHook), AccessTools.all)));
            }
#elif AI || HS2
            //Hooks for changing clothing pattern
            foreach (var method in typeof(CharaCustom.CustomClothesPatternSelect).GetMethods(AccessTools.all).Where(x => x.Name.Contains("<ChangeLink>")))
            {
                harmony.Patch(method, new HarmonyMethod(typeof(Hooks).GetMethod(nameof(Hooks.ClothesColorChangeHook), AccessTools.all)));
            }

            //hooks for changing clothing color
            foreach (var method in typeof(CharaCustom.CustomClothesColorSet).GetMethods(AccessTools.all).Where(x => x.Name.StartsWith("<Initialize>")))
            {
                harmony.Patch(method, new HarmonyMethod(typeof(Hooks).GetMethod(nameof(Hooks.ClothesColorChangeHook), AccessTools.all)));
            }
#endif
            StartCoroutine(LoadXML());
            StartCoroutine(GetUncensorSelectorParts());

            ResourceRedirection.RegisterAssetLoadedHook(HookBehaviour.OneCallbackPerResourceLoaded, AssetLoadedHook);
        }
        static bool MM_Detour(AsyncOperation self)
        {
            if (ResourceRedirection.ShouldBlockAsyncOperationMethods(self))
            {
                return(true); // do not believe this has an impact
            }

            return(_original(self));
        }
        static void MM_Detour(AsyncOperation self)
        {
            if (ResourceRedirection.ShouldBlockAsyncOperationMethods(self))
            {
                return;
            }

            _original(self);
        }
        static int MM_Detour(AsyncOperation self)
        {
            if (ResourceRedirection.ShouldBlockAsyncOperationMethods(self))
            {
                return(0);
            }

            return(_original(self));
        }
        static UnityEngine.Object[] MM_Detour(string path, Type systemTypeInstance)
        {
            var result = _original(path, systemTypeInstance);

            var parameters = new ResourceLoadedParameters(path, systemTypeInstance, ResourceLoadType.LoadByType);

            ResourceRedirection.Hook_ResourceLoaded_Postfix(parameters, ref result);

            return(result);
        }
        static UnityEngine.Object MM_Detour(Type systemTypeInstance, string path)
        {
            var result = _original(systemTypeInstance, path);

            var parameters = new ResourceLoadedParameters(path, systemTypeInstance, ResourceLoadType.LoadNamedBuiltIn);

            ResourceRedirection.Hook_ResourceLoaded_Postfix(parameters, ref result);

            return(result);
        }
Ejemplo n.º 23
0
        void Awake()
        {
            ResourceRedirection.RegisterAssetBundleLoadingHook(
                priority: 1000,
                action: AssetBundleLoading);

            ResourceRedirection.RegisterAsyncAssetBundleLoadingHook(
                priority: 1000,
                action: AsyncAssetBundleLoading);
        }
Ejemplo n.º 24
0
        public void Awake()
        {
            ResourceRedirection.EnableSyncOverAsyncAssetLoads();

            if (Directory.Exists(IntroClipsDirectory))
            {
                ResourceRedirection.RegisterAsyncAndSyncAssetLoadingHook(LoadIntroClips);
            }
            if (Directory.Exists(BGMDirectory))
            {
                ResourceRedirection.RegisterAsyncAndSyncAssetLoadingHook(LoadBGM);
            }
        }
Ejemplo n.º 25
0
        static AssetBundleCreateRequest MM_Detour(string path, uint crc, ulong offset)
        {
            AssetBundleCreateRequest result;

            var context = ResourceRedirection.Hook_AssetBundleLoading_Prefix(path, crc, offset, AssetBundleLoadType.LoadFromFile, out result);

            if (!context.SkipOriginalCall)
            {
                var p = context.Parameters;
                result = _original(p.Path, p.Crc, p.Offset);
            }

            ResourceRedirection.Hook_AssetBundleLoading_Postfix(context, result);

            return(result);
        }
Ejemplo n.º 26
0
        static AssetBundleCreateRequest MM_Detour(Stream stream, uint crc, uint managedReadBufferSize)
        {
            AssetBundleCreateRequest result;

            var parameters = new AssetBundleLoadingParameters(null, null, crc, 0, stream, managedReadBufferSize, AssetBundleLoadType.LoadFromMemory);
            var context    = ResourceRedirection.Hook_AssetBundleLoading_Prefix(parameters, out result);

            if (!context.SkipOriginalCall)
            {
                var p = context.Parameters;
                result = _original(p.Stream, p.Crc, p.ManagedReadBufferSize);
            }

            ResourceRedirection.Hook_AssetBundleLoading_Postfix(context, result);

            return(result);
        }
        static AssetBundleCreateRequest MM_Detour(byte[] binary, uint crc)
        {
            AssetBundleCreateRequest result;

            var parameters = new AssetBundleLoadingParameters(binary, null, crc, 0, AssetBundleLoadType.LoadFromMemory);
            var context    = ResourceRedirection.Hook_AssetBundleLoading_Prefix(parameters, out result);

            if (!context.SkipOriginalCall)
            {
                var p = context.Parameters;
                result = _original(p.Binary, p.Crc);
            }

            ResourceRedirection.Hook_AssetBundleLoading_Postfix(context, result);

            return(result);
        }
Ejemplo n.º 28
0
        static AssetBundleRequest MM_Detour(AssetBundle self, string name, Type type)
        {
            AssetBundleRequest result = null;

            var context = ResourceRedirection.Hook_AsyncAssetLoading_Prefix(name, type, AssetLoadType.LoadNamed, self, ref result);

            var p = context.Parameters;

            if (!context.SkipOriginalCall)
            {
                result = _original(self, p.Name, p.Type);
            }

            ResourceRedirection.Hook_AssetLoading_Postfix(context, result);

            return(result);
        }
Ejemplo n.º 29
0
        static UnityEngine.Object MM_Detour(AssetBundle self)
        {
            UnityEngine.Object result = null;

            var context = ResourceRedirection.Hook_AssetLoading_Prefix(null, null, AssetLoadType.LoadMainAsset, self, ref result);

            if (!context.SkipOriginalCall)
            {
                result = _original(self);
            }

            if (!context.SkipAllPostfixes)
            {
                ResourceRedirection.Hook_AssetLoaded_Postfix(null, null, AssetLoadType.LoadMainAsset, self, null, ref result);
            }

            return(result);
        }
Ejemplo n.º 30
0
        public virtual void Awake()
        {
            Instance = this;
            Logger   = base.Logger;
            Directory.CreateDirectory(ExportPath);

            UIScale = Config.Bind("Config", "UI Scale", 1.75f, new ConfigDescription("Controls the size of the window.", new AcceptableValueRange <float>(1f, 3f), new ConfigurationManagerAttributes {
                Order = 5
            }));
            UIWidth = Config.Bind("Config", "UI Width", 0.3f, new ConfigDescription("Controls the size of the window.", new AcceptableValueRange <float>(0f, 1f), new ConfigurationManagerAttributes {
                Order = 4, ShowRangeAsPercent = false
            }));
            UIHeight = Config.Bind("Config", "UI Height", 0.3f, new ConfigDescription("Controls the size of the window.", new AcceptableValueRange <float>(0f, 1f), new ConfigurationManagerAttributes {
                Order = 3, ShowRangeAsPercent = false
            }));
            WatchTexChanges = Config.Bind("Config", "Watch File Changes", true, new ConfigDescription("Watch for file changes and reload textures on change. Can be toggled in the UI.", null, new ConfigurationManagerAttributes {
                Order = 2
            }));
            ShaderOptimization = Config.Bind("Config", "Shader Optimization", true, new ConfigDescription("Replaces every loaded shader with the MaterialEditor copy of the shader. Reduces the number of copies of shaders loaded which reduces RAM usage and improves performance.", null, new ConfigurationManagerAttributes {
                Order = 1
            }));
            ExportBakedMesh = Config.Bind("Config", "Export Baked Mesh", false, new ConfigDescription("When enabled, skinned meshes will be exported in their current state with all customization applied as well as in the current pose.", null, new ConfigurationManagerAttributes {
                Order = 1
            }));
            ExportBakedWorldPosition = Config.Bind("Config", "Export Baked World Position", false, new ConfigDescription("When enabled, objects will be exported with their position changes intact so that, i.e. when exporting two objects they retain their position relative to each other.\nOnly works when Export Baked Mesh is also enabled.", null, new ConfigurationManagerAttributes {
                Order = 1
            }));
            ConfigExportPath = Config.Bind("Config", "Export Path Override", "", new ConfigDescription($"Textures and models will be exported to this folder. If empty, exports to {ExportPathDefault}", null, new ConfigurationManagerAttributes {
                Order = 1
            }));

            UIScale.SettingChanged            += MaterialEditorUI.UISettingChanged;
            UIWidth.SettingChanged            += MaterialEditorUI.UISettingChanged;
            UIHeight.SettingChanged           += MaterialEditorUI.UISettingChanged;
            WatchTexChanges.SettingChanged    += WatchTexChanges_SettingChanged;
            ShaderOptimization.SettingChanged += ShaderOptimization_SettingChanged;
            ConfigExportPath.SettingChanged   += ConfigExportPath_SettingChanged;
            SetExportPath();

            ResourceRedirection.RegisterAssetLoadedHook(HookBehaviour.OneCallbackPerResourceLoaded, AssetLoadedHook);
            LoadXML();
        }