Example #1
0
        public virtual List <List <string> > GetExcelHeaderRows(ExcelData asset, out int firstRow)
        {
            var headerRows = new List <List <string> >();

            firstRow = 0;
            var headerRow = asset.GetRow(firstRow++);

            headerRows.Add(headerRow);

            var numEmpty    = headerRow.Count(h => h.IsNullOrWhiteSpace());
            var hiddenIndex = headerRow.IndexOf("非表示オブジェクト");

            if (headerRow.Count == numEmpty ||
                headerRow.Count > 1 && headerRow[1].IsNullOrWhiteSpace() && (
                    headerRow[0].StartsWith("H") ||
                    headerRow[0] == "主人公"))

            {
                headerRows.Add(asset.GetRow(firstRow++));
            }
            else if (hiddenIndex == -1 && numEmpty > 3 || numEmpty / (headerRow.Count * 1.0) > 0.49)
            {
                var testRow  = asset.GetRow(firstRow);
                var testData = asset.GetRow(firstRow + 1);
                if (testRow.Count > 1)
                {
                    if (testRow[0] == "表示順番" || testRow[0] == "管理番号" ||
                        testData.Count > 1 && int.TryParse(testData[0], out _) && !int.TryParse(testRow[0], out _))
                    {
                        headerRows.Add(testRow);
                        firstRow++;
                    }
                }
            }
            else if (hiddenIndex > 0)
            {
                var testRow = asset.GetRow(firstRow);
                if (testRow.Count > hiddenIndex && testRow[0].IsNullOrEmpty() && !testRow[hiddenIndex].IsNullOrEmpty())
                {
                    var dataRow = asset.GetRow(firstRow + 1);
                    if (dataRow.Count > 0 && !dataRow[0].IsNullOrEmpty())
                    {
                        firstRow++;
                        headerRows.Add(testRow);
                    }
                }
            }


            var rowNum = -1;

            foreach (var row in headerRows)
            {
                rowNum++;
                Logger.DebugLogDebug(
                    $"{nameof(GetExcelHeaderRows)}: {asset.name}: firstRow={firstRow}, headerRows[{rowNum}]='{string.Join("', '", row.ToArray())}'");
            }

            return(headerRows);
        }
Example #2
0
        private void SelectCharasById(CharaId matchId)
        {
            var selected      = 0;
            var origCharCount = StudioAPI.GetSelectedCharacters().Count();
            var origObjCount  = StudioAPI.GetSelectedObjects().Count() - origCharCount;

            foreach (var objectCtrlInfo in EnumerateObjects())
            {
                Logger.DebugLogDebug($"SelectCharasById: {objectCtrlInfo}");
                if (objectCtrlInfo is OCIChar ociChar)
                {
                    if (DoesCharaMatch(matchId, ociChar))
                    {
                        ociChar.MultiSelectInWorkarea();
                        selected++;
                    }
                    else
                    {
                        if (ociChar.IsSelectedInWorkarea())
                        {
                            ociChar.UnselectInWorkarea();
                        }
                    }
                }
                else
                {
                    objectCtrlInfo.UnselectInWorkarea();
                }
            }

            Logger.Log(BepInLogLevel.Info | BepInLogLevel.Message,
                       $"characters selected: {selected} ({selected - origCharCount} new selections, {origObjCount} non-characters unselected)");
            GeBoAPI.Instance.PlayNotificationSound(NotificationSound.Success);
        }
Example #3
0
        internal static bool EnabledForCurrentHeroine()
        {
            var result = CurrentlyEnabled && _logic.EnabledForHeroine(TargetHeroine);

            Logger?.DebugLogDebug($"EnabledForCurrentHeroine => {result}");
            return(result);
        }
Example #4
0
        internal void DressPlayer(ChaFileDefine.CoordinateType newCoordinateType)
        {
            if (!_monitoringChange || !Game.IsInstance() || Game.Instance == null)
            {
                return;
            }

            var player = Game.Instance.Player;

            if (player == null)
            {
                return;
            }


            var mode = Mode.Value;

            var playerClothesIsAuto = player.changeClothesType < 0;
            var playerShouldChange  = playerClothesIsAuto || mode == PluginMode.Always;

            Logger.DebugLogDebug(
                $"{nameof(DressPlayer)}: mode={mode}, playerClothesIsAuto={playerClothesIsAuto}, playerShouldChange={playerShouldChange}");

            if (!playerShouldChange)
            {
                return;
            }

            player.chaCtrl.SafeProc(cc =>
            {
                if (!cc.ChangeCoordinateTypeAndReload(newCoordinateType))
                {
                    return;
                }
                Logger.LogDebug($"Changed player clothes to {newCoordinateType}");
                if (!playerClothesIsAuto)
                {
                    // update selected clothes to match so you can change back
                    player.changeClothesType = (int)newCoordinateType;
                }
            });

            _monitoringChange = false;
        }
        public override TextAndEncoding TranslateTextAsset(string calculatedModificationPath, TextAsset asset,
                                                           IAssetOrResourceLoadedContext context)
        {
            Logger.DebugLogDebug($"{GetType()} attempt to handle {calculatedModificationPath}");
            if (!Enabled || asset.bytes == null)
            {
                Logger.DebugLogDebug($"{GetType()} unable to handle {calculatedModificationPath}");
                return(null);
            }

            byte[] bytes       = null;
            var    defaultFile = Path.Combine(calculatedModificationPath, "translation.bytes");

            if (File.Exists(defaultFile))
            {
                bytes = File.ReadAllBytes(defaultFile);
            }

            if (bytes == null || bytes.Length == 0)
            {
                foreach (var entry in RedirectedDirectory.GetFilesInDirectory(calculatedModificationPath, ".bytes"))
                {
                    using (var stream = entry.OpenStream())
                    {
                        bytes = ReadBytes(stream);
                    }

                    if (bytes.Length > 0)
                    {
                        break;
                    }
                }
            }

            if (bytes == null || bytes.Length == 0)
            {
                Logger.DebugLogDebug($"{GetType()}  unable to handle {calculatedModificationPath}: no .bytes files");
                return(null);
            }

            Logger.DebugLogDebug($"{GetType()} handled {calculatedModificationPath}");
            return(new TextAndEncoding(bytes, _textResourceHelper.TableHelper.TextAssetEncoding));
        }
Example #6
0
        private void SaveTrackingFile()
        {
            Logger.DebugLogDebug($"{nameof(SaveTrackingFile)} fired");
            if (!SavePending)
            {
                return;
            }
            if (TrackLastLoadedSceneFile == null)
            {
                throw new NullReferenceException($"{nameof(TrackLastLoadedSceneFile)} should not be null");
            }

            var prefix  = Path.Combine(Paths.CachePath, Path.GetFileName(TrackLastLoadedSceneFile));
            var newFile = string.Concat(prefix, Path.GetRandomFileName());
            var oldFile = string.Concat(prefix, Path.GetRandomFileName());

            var relativeScenes = DictionaryPool <string, string> .Get();

            try
            {
                foreach (var entry in LastLoadedScenes)
                {
                    relativeScenes[SceneRelativePathCache.Get(entry.Key)] =
                        Path.GetFileName(entry.Value);
                }

                lock (SavePendingLock)
                {
                    if (!SavePending)
                    {
                        return;
                    }

                    try
                    {
                        using (var fileStream = new FileStream(newFile, FileMode.Create))
                            using (var streamWriter = new StreamWriter(fileStream, Encoding.UTF8))
                            {
                                streamWriter.Write(GUID);
                                streamWriter.Write(TrackingFileEntrySplit[0]);
                                streamWriter.Write(Version);
                                streamWriter.Write(TrackingFileEntrySplit[0]);
                                streamWriter.Write(relativeScenes.Count);
                                streamWriter.Write(TrackingFileEntrySplit[0]);
                                streamWriter.Write('\n');
                                foreach (var entry in relativeScenes)
                                {
                                    streamWriter.Write(entry.Key);
                                    streamWriter.Write(TrackingFileEntrySplit[0]);
                                    streamWriter.Write(entry.Value);
                                    streamWriter.Write('\n');
                                }
                            }

                        File.Move(TrackLastLoadedSceneFile, oldFile);
                        File.Move(newFile, TrackLastLoadedSceneFile);
                        File.Delete(oldFile);
                        SavePending = false;
                        Logger.DebugLogDebug($"Updated {TrackLastLoadedSceneFile}");
                    }
                    catch (Exception err)
                    {
                        if (!File.Exists(oldFile))
                        {
                            throw;
                        }
                        Logger.LogException(err, this,
                                            $"{nameof(SaveTrackingFile)}: Error encountered, restoring {TrackLastLoadedSceneFile}");

                        File.Copy(oldFile, TrackLastLoadedSceneFile);

                        throw;
                    }
                    finally
                    {
                        if (File.Exists(oldFile))
                        {
                            File.Delete(oldFile);
                        }
                        if (File.Exists(newFile))
                        {
                            File.Delete(newFile);
                        }
                    }
                }
            }
            finally
            {
                DictionaryPool <string, string> .Release(relativeScenes);
            }
        }
        public IEnumerable <ResourceMappingPath> GetMappingForPath(ResourceMappingPath path, ResourceMappingMode mode)
        {
            Logger.LogDebug($"{nameof(GetMappingForPath)}: path={path}");

            if (IsPathUnmapped(path, mode))
            {
                Logger.DebugLogDebug($"{nameof(GetMappingForPath)}: {path}: unmapped");
                yield break;
            }

            if (TryGetCachedMappingPaths(path, mode, out var cachedMappedPaths))
            {
                foreach (var mappedPath in cachedMappedPaths)
                {
                    yield return(mappedPath);
                }
                Logger.DebugLogDebug($"{nameof(GetMappingForPath)}: {path}: used cached");
                yield break;
            }

            cachedMappedPaths = new List <ResourceMappingPath>();
            var seenPaths = new HashSet <ResourceMappingPath> {
                path
            };

            using (var mappersForPath = GetMappersForPath(path, mode).GetEnumerator())
            {
                while (true)
                {
                    try
                    {
                        if (!mappersForPath.MoveNext())
                        {
                            break;
                        }
                    }
                    catch (Exception err)
                    {
                        Logger.LogDebug($"{nameof(GetMappingForPath)}: {err.Message}");
                        UnityEngineDebug.LogException(err);
                        continue;
                    }

                    var mapper = mappersForPath.Current;
                    // shouldn't happen
                    if (mapper == null)
                    {
                        continue;
                    }

                    using (var mappedPaths = mapper(path, mode).GetEnumerator())
                    {
                        while (true)
                        {
                            try
                            {
                                if (!mappedPaths.MoveNext())
                                {
                                    break;
                                }
                            }
                            catch (Exception err)
                            {
                                Logger.LogDebug($"{nameof(GetMappingForPath)}: {mapper.Method.Name}: {err.Message}");
                                UnityEngineDebug.LogException(err);
                                continue;
                            }

                            var mappedPath = mappedPaths.Current;
                            if (mappedPath == null || seenPaths.Contains(mappedPath))
                            {
                                continue;
                            }

                            yield return(mappedPath);

                            seenPaths.Add(mappedPath);
                            cachedMappedPaths.Add(mappedPath);
                        }
                    }
                }
            }

            if (cachedMappedPaths.Count == 0)
            {
                SetPathUnmapped(path, mode);
            }
            else
            {
                SetCachedMappingPaths(path, mode, cachedMappedPaths);
                Logger.LogDebug(
                    $"{nameof(GetMappingForPath)}: {path} => {string.Join(", ", cachedMappedPaths.Select(p=>p.ResourcePath).ToArray())}");
            }
        }