Exemplo n.º 1
0
 public static bool Patch_JsonConvert(string str, ref OutputNode __result)
 {
     if (str.StartsWith("[JSON", StringComparison.CurrentCultureIgnoreCase))
     {
         try
         {
             string jsonStr;
             if (str.StartsWith("[JSONFILE", StringComparison.CurrentCultureIgnoreCase))
             {
                 var array = Game.Resource.LoadBytes(str.Substring(10)); // remove [JSONFILE]
                 jsonStr = Encoding.UTF8.GetString(array);
             }
             else
             {
                 jsonStr = str.Substring(6);           // remove [JSON]
             }
             jsonStr = GlobalLib.ReplaceText(jsonStr); // preprocess
             Console.WriteLine("parse json: " + jsonStr);
             __result = ModJson.FromJsonMod <OutputNode>(jsonStr);
         }
         catch (Exception e)
         {
             Debug.LogError(e);
             Debug.LogError("解析Json错误" + str);
             throw;
         }
         return(false);
     }
     return(true);
 }
Exemplo n.º 2
0
 public static bool Patch_MovieLoadJson(ref object __result, JsonReader reader)
 {
     if (reader.TokenType == JsonToken.String)
     {
         __result = OutputNodeConvert.Deserialize(reader.Value.ToString());
     }
     else
     {
         // 增加json加载
         //Console.WriteLine("检测到Json模式Node!");
         __result = ModJson.FromReaderMod <OutputNode>(reader);
     }
     return(false);
 }
Exemplo n.º 3
0
 public static bool Patch_ScheduleLoad2(WuxiaBattleSchedule __instance, ref string ScheduleID)
 {
     if (!ScheduleID.IsNullOrEmpty())
     {
         string path = string.Format(GameConfig.BattleSchedulePath, GameConfig.Language, ScheduleID + ".json");
         try
         {
             Traverse.Create(__instance).Property("BattleSchedule").SetValue(ModJson.FromJsonResource <BattleSchedule>(path, true));
         }
         catch
         {
             Debug.Log("無法讀取 : " + path);
         }
     }
     ScheduleID = null;  //skip original load
     return(true);
 }
Exemplo n.º 4
0
 public static bool Patch_ScheduleLoad3(WuxiaBattleBuffer __instance, WuxiaUnit unit, string bufferId, bool _is_born, bool _first)
 {
     if (bufferId.IsNullOrEmpty())
     {
         Heluo.Logger.LogError("要附加的BufferId是空值", "AddBuffer", "C:\\PathOfWuxia\\PathOfWuxia\\Assets\\Scripts\\Battle\\WuxiaBattleBuffer.cs", 119);
         return(false);
     }
     try
     {
         string            path   = string.Format(GameConfig.ButtleBufferPath, GameConfig.Language, bufferId + ".json");
         Heluo.Data.Buffer buffer = ModJson.FromJsonResource <Heluo.Data.Buffer>(path, false);    // buff大概不用替换id吧..
         __instance.AddBuffer(unit, buffer, _is_born, _first);
     }
     catch
     {
         Heluo.Logger.LogError("附加Buffer : " + bufferId + " 失敗", "AddBuffer", "C:\\PathOfWuxia\\PathOfWuxia\\Assets\\Scripts\\Battle\\WuxiaBattleBuffer.cs", 135);
     }
     return(false);
 }
Exemplo n.º 5
0
 public static bool Patch_ScheduleLoad(SchedulerComponent __instance, ref ScheduleGraph __result, string path)
 {
     // 取消Dictionary Cache,性能不太可能有问题
     if (string.IsNullOrEmpty(path))
     {
         Heluo.Logger.Log("排程为空", Heluo.Logger.LogLevel.ERROR, "white", "GetScheduleGraph", "C:\\PathOfWuxia\\PathOfWuxia\\Assets\\Scripts\\Features\\SchedulerComponent.cs", 162);
         __result = null;
         return(false);
     }
     try
     {
         ScheduleGraph.Bundle bundle = ModJson.FromJsonResource <ScheduleGraph.Bundle>(path, true);
         __result = new ScheduleGraph(bundle);
     }
     catch
     {
         Heluo.Logger.Log("Path = " + path + " 解析失败", Heluo.Logger.LogLevel.ERROR, "white", "GetScheduleGraph", "C:\\PathOfWuxia\\PathOfWuxia\\Assets\\Scripts\\Features\\SchedulerComponent.cs", 162);
         __result = null;
     }
     return(false);
 }
Exemplo n.º 6
0
        public void OnUpdate()
        {
            if (!DebugOn.Value)
            {
                return;
            }
            if (Input.GetKeyDown(NodeDocKey.Value))
            {
                string target = DebugOutDir.Value + "游戏指令(OutputNode)文档.json";
                ModOutputNodeConverter.ExportDoc(target);
                target = DebugOutDir.Value + "txt表格(Item)文档.json";
                ItemDocConverter.ExportDoc(target);
            }
            if (Input.GetKeyDown(NodeFileKey.Value) && !string.IsNullOrEmpty(NodeContent.Value))
            {
                // OutputNode
                string     target     = DebugOutDir.Value + NodeFilePath.Value;
                OutputNode obj        = OutputNodeConvert.Deserialize(NodeContent.Value);
                var        strJsonMod = ModJson.ToJsonMod(obj, typeof(OutputNode), JsonPritty.Value);
                Console.WriteLine("Json版 = " + strJsonMod);
                GlobalLib.ToFile(strJsonMod, target);
            }
            if (Input.GetKeyDown(MovieFileKey.Value) && !string.IsNullOrEmpty(MovieFileId.Value))
            {
                // movie
                string source = string.Format(MovieFileType.Value == MovieType.Cinematic ? GameConfig.CinematicPath : GameConfig.SchedulerPath, MovieFileId.Value);
                string target = string.Format(DebugOutDir.Value + MovieFilePath.Value, MovieFileId.Value);
                var    obj    = ModJson.FromJsonResource <ScheduleGraph.Bundle>(source);
                if (JsonFormat.Value)
                {
                    var strJsonMod = ModJson.ToJsonMod(obj, typeof(ScheduleGraph.Bundle), JsonPritty.Value);
                    Console.WriteLine("Json版 = " + strJsonMod);
                    GlobalLib.ToFile(strJsonMod, target);

                    // 测试读取并对比重新通过Json构建的是否有差
                    var obj2 = ModJson.FromJsonMod <ScheduleGraph.Bundle>(strJsonMod);
                    JsonSerializerSettings originalSetting = new JsonSerializerSettings
                    {
                        Converters = new JsonConverter[]
                        {
                            new OutputNodeJsonConverter()
                        }
                    };
                    string str2 = ModJson.ToJson(obj2, typeof(ScheduleGraph.Bundle), originalSetting, JsonPritty.Value);
                    Console.WriteLine("重构脚本 = " + str2);
                }
                else
                {
                    GlobalLib.ToFile(Game.Resource.LoadString(source), target);
                }
            }
            if (Input.GetKeyDown(BattleFileKey.Value) && !string.IsNullOrEmpty(BattleFileId.Value))
            {
                // battle schedule
                string source = string.Format(GameConfig.BattleSchedulePath, GameConfig.Language, BattleFileId.Value + ".json");
                string target = string.Format(DebugOutDir.Value + BattleFilePath.Value, BattleFileId.Value);
                if (JsonFormat.Value)
                {
                    BattleSchedule obj        = ModJson.FromJsonResource <BattleSchedule>(source);
                    var            strJsonMod = ModJson.ToJsonMod(obj, typeof(BattleSchedule), JsonPritty.Value);
                    Console.WriteLine("Json版 = " + strJsonMod);
                    GlobalLib.ToFile(strJsonMod, target);
                }
                else
                {
                    GlobalLib.ToFile(Game.Resource.LoadString(source), target);
                }
            }
            if (Input.GetKeyDown(BuffFileKey.Value) && !string.IsNullOrEmpty(BuffFileId.Value))
            {
                // buff
                string source = string.Format(GameConfig.ButtleBufferPath, GameConfig.Language, BuffFileId.Value + ".json");
                string target = string.Format(DebugOutDir.Value + BuffFilePath.Value, BuffFileId.Value);
                if (JsonFormat.Value)
                {
                    Heluo.Data.Buffer obj = ModJson.FromJsonResource <Heluo.Data.Buffer>(source);
                    var strJsonMod        = ModJson.ToJsonMod(obj, typeof(Heluo.Data.Buffer), true);
                    Console.WriteLine("Json版 = " + strJsonMod);
                    GlobalLib.ToFile(strJsonMod, target);
                }
                else
                {
                    GlobalLib.ToFile(Game.Resource.LoadString(source), target);
                }
            }
        }