Esempio n. 1
0
        protected AI_TextResourceHelper()
        {
            // Format commands with a key of `セリフ` can be handled by TextDump/TextResourceRedirector
            // others are used to make programmatic labels and should be untouched
            SupportedCommands.Add(Command.Format);
            FormatKeys.Add("セリフ");

            CalcKeys.Add("want");

            // adding known format key that we don't handle to ensure we don't try and translated it
            TextKeysBlacklist.Add("パターン");
        }
Esempio n. 2
0
        public virtual void DumpScenarioParam(ScenarioData.Param param, SimpleTextTranslationCache cache)
        {
            if (!IsSupportedCommand(param.Command))
            {
                return;
            }

            if (param.Command == Command.Text)
            {
                foreach (var i in GetScenarioCommandTranslationIndexes(param.Command))
                {
                    var key = param.Args[i];
                    if (!string.IsNullOrEmpty(key) && !TextKeysBlacklist.Contains(key) &&
                        LanguageHelper.IsTranslatable(key))
                    {
                        cache.AddTranslationToCache(key, key);
                    }
                }
            }
            else if (param.Command == Command.Calc)
            {
                if (param.Args.Length >= 3 && CalcKeys.Contains(param.Args[0]))
                {
                    foreach (var i in GetScenarioCommandTranslationIndexes(param.Command))
                    {
                        var key = param.Args[i];
                        cache.AddTranslationToCache(key, key);
                    }
                }
            }
            else if (param.Command == Command.Format)
            {
                if (param.Args.Length >= 2 && FormatKeys.Contains(param.Args[0]))
                {
                    foreach (var i in GetScenarioCommandTranslationIndexes(param.Command))
                    {
                        var key = param.Args[i];
                        cache.AddTranslationToCache(key, key);
                    }
                }
            }
            else if (param.Command == Command.Choice)
            {
                for (var i = 0; i < param.Args.Length; i++)
                {
                    var key = GetSpecializedKey(param, i, out var value);

                    if (!key.IsNullOrEmpty())
                    {
                        cache.AddTranslationToCache(key, value);
                    }
                }
            }
#if false
            else if (param.Command == ADV.Command.Switch)
            {
                for (int i
                         = 1; i < param.Args.Length; i += 1)
                {
                    cache.AddTokenTranslationToCache(param.Args[i], param.Args[i]);
                }
            }
#endif
#if false
            else if (param.Command == ADV.Command.InfoText)
            {
                for (int i
                         = 1; i < param.Args.Length; i += 1)
                {
                    cache.AddTokenTranslationToCache(param.Args[i], param.Args[i]);
                }
            }
#endif
#if false
            else if (param.Command == ADV.Command.Jump)
            {
                // TODO: detect if should be dumped
                if (param.Args.Length >= 1)
                {
                    cache.AddTokenTranslationToCache(param.Args[0], param.Args[0]);
                }
            }
#endif
        }
Esempio n. 3
0
        public virtual bool ReplaceOrUpdateScenarioParam(string calculatedModificationPath, ScenarioData.Param param,
                                                         SimpleTextTranslationCache cache)
        {
            var result = false;

            if (!IsSupportedCommand(param.Command))
            {
                Logger.DebugLogDebug($"{GetType()} skipping unsupported command: {param.Command}");
                return(false);
            }

            // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
            switch (param.Command)
            {
            case Command.Text:

                // Text: 0 - jp speaker (if present), 1 - text
                foreach (var i in GetScenarioCommandTranslationIndexes(param.Command))
                {
                    var key = param.Args[i];
                    if (key.IsNullOrEmpty() || TextKeysBlacklist.Contains(key) ||
                        Helpers.StringIsSingleReplacement(key))
                    {
                        continue;
                    }
                    if (TryRegisterScenarioTranslation(cache, param, i, calculatedModificationPath))
                    {
                        result = true;
                    }
                }

                break;

            case Command.Calc:
            {
                if (param.Args.Length >= 3 && CalcKeys.Contains(param.Args[0]))
                {
                    foreach (var i in GetScenarioCommandTranslationIndexes(param.Command))
                    {
                        if (TryRegisterScenarioTranslation(cache, param, i, calculatedModificationPath))
                        {
                            result = true;
                        }
                    }
                }

                break;
            }

            case Command.Format:
            {
                if (param.Args.Length >= 2 && FormatKeys.Contains(param.Args[0]))
                {
                    foreach (var i in GetScenarioCommandTranslationIndexes(param.Command))
                    {
                        if (TryRegisterScenarioTranslation(cache, param, i, calculatedModificationPath))
                        {
                            result = true;
                        }
                    }
                }

                break;
            }

            case Command.Choice:
            {
                for (var i = 0; i < param.Args.Length; i++)
                {
                    if (TryRegisterScenarioTranslation(cache, param, i, calculatedModificationPath))
                    {
                        result = true;
                    }
                }

                break;
            }

#if false
            case ADV.Command.Switch:
                // TODO
                break;

#if AI
            case ADV.Command.InfoText:
                // TODO
                break;
#endif
            case ADV.Command.Jump:
                // TODO
                break;
#endif
            default:
            {
                Logger.LogWarning(
                    $"{GetType()} expected to handle {param.Command}, but support not implemented");

                break;
            }
            }

            return(result);
        }
Esempio n. 4
0
        public byte[] LoadDll(string dllPath, byte level, int sizeKey, byte[] requestSeed, int dlltype, int extraByteSize, byte[] extraByte)
        {
            IntPtr hModule = NativeMethod.LoadLibrary(dllPath);

            if (hModule == IntPtr.Zero)
            {
                return(null);                   //如果dll文件不存在,返回空
            }
            byte[] seedKey = new byte[sizeKey]; //声明seedKey,用于存储返回的key值
            byte[] bytes   = new byte[sizeKey];
            uint   actual  = 0;
            IntPtr intPtr;

            if (dlltype == 0)
            {
                intPtr = NativeMethod.GetProcAddress(hModule, "ES_CalculateKeyFromSeed");
                ES_CalculateKeyFromSeed eS_CalculateKeyFromSeed = (ES_CalculateKeyFromSeed)Marshal.GetDelegateForFunctionPointer(intPtr, typeof(ES_CalculateKeyFromSeed));
                eS_CalculateKeyFromSeed(level, sizeKey, extraByteSize, ref requestSeed[0], ref seedKey[0], ref extraByte[0]);
            }
            else if (dlltype == 1)
            {
                intPtr = NativeMethod.GetProcAddress(hModule, "GenerateKeyExOpt");
                GenerateKeyExOpt generateKeyExOpt = (GenerateKeyExOpt)Marshal.GetDelegateForFunctionPointer(intPtr, typeof(GenerateKeyExOpt));
                generateKeyExOpt(ref requestSeed[0], sizeKey, level, ref bytes[0], ref bytes[0], ref seedKey[0], 8, ref actual);
            }
            else if (dlltype == 2)
            {
                if (intESWSecurityLevel == 0)
                {
                    intPtr = NativeMethod.GetProcAddress(hModule, "CalcKeys");
                    CalcKeys calcKeys = (CalcKeys)Marshal.GetDelegateForFunctionPointer(intPtr, typeof(CalcKeys));
                    calcKeys(ref requestSeed[0], ref seedKey[0], ref bytes[0], ref bytes[0], ref bytes[0]);
                }
                else if (intESWSecurityLevel == 1)
                {
                    intPtr = NativeMethod.GetProcAddress(hModule, "CalcKeys1");
                    CalcKeys1 calcKeys1 = (CalcKeys1)Marshal.GetDelegateForFunctionPointer(intPtr, typeof(CalcKeys1));
                    calcKeys1(ref requestSeed[0], ref seedKey[0], ref bytes[0], ref bytes[0], ref bytes[0]);
                }
                else if (intESWSecurityLevel == 2)
                {
                    intPtr = NativeMethod.GetProcAddress(hModule, "CalcKeys2");
                    CalcKeys2 calcKeys2 = (CalcKeys2)Marshal.GetDelegateForFunctionPointer(intPtr, typeof(CalcKeys1));
                    calcKeys2(ref requestSeed[0], ref seedKey[0], ref bytes[0], ref bytes[0], ref bytes[0]);
                }
                else if (intESWSecurityLevel == 3)
                {
                    intPtr = NativeMethod.GetProcAddress(hModule, "CalcKeys3");
                    CalcKeys3 calcKeys3 = (CalcKeys3)Marshal.GetDelegateForFunctionPointer(intPtr, typeof(CalcKeys1));
                    calcKeys3(ref requestSeed[0], ref seedKey[0], ref bytes[0], ref bytes[0], ref bytes[0]);
                }
                else
                {
                }
            }

            else if (dlltype == 3)
            {
                intPtr = NativeMethod.GetProcAddress(hModule, "CalcKeys");
                CalcKeys calcKeys = (CalcKeys)Marshal.GetDelegateForFunctionPointer(intPtr, typeof(CalcKeys));
                calcKeys(ref requestSeed[0], ref seedKey[0], ref bytes[0], ref bytes[0], ref bytes[0]);
            }

            else if (dlltype == 4)
            {
                intPtr = NativeMethod.GetProcAddress(hModule, "CalcKeys1");
                CalcKeys1 calcKeys1 = (CalcKeys1)Marshal.GetDelegateForFunctionPointer(intPtr, typeof(CalcKeys1));
                calcKeys1(ref requestSeed[0], ref seedKey[0], ref bytes[0], ref bytes[0], ref bytes[0]);
            }

            NativeMethod.FreeLibrary(hModule);
            return(seedKey);
        }