<commit_before>﻿using Microsoft.Xna.Framework.Content;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ContentCompiler
{
    class Program
    {
        static void Main(string[] args)
        {
            Decompile();
        }
        static ContentManager SetupContentManager(string root)
        {

            var serviceContainer = new Microsoft.Xna.Framework.GameServiceContainer();
            var content = new Microsoft.Xna.Framework.Content.ContentManager(serviceContainer, root);
            var graphicsDevice = new Microsoft.Xna.Framework.GraphicsDeviceManager(new Game1());
            serviceContainer.AddService<Microsoft.Xna.Framework.Graphics.IGraphicsDeviceService>(graphicsDevice);
            return content;
        }
        static void Decompile()
        {
            var root = @"F:\steam\steamapps\common\Stardew Valley\Content";
            var content = SetupContentManager(root);

            var characters = Directory.EnumerateFiles(root + "\\characters\\schedules").Where(c=>Path.GetExtension(c)==".xnb").Select(c=>Path.GetFileNameWithoutExtension(c));
            foreach (var character in characters)
            {
                var scheduleRaw = content.Load<Dictionary<string, string>>("characters\\schedules\\" + character);
                var json = JsonConvert.SerializeObject(scheduleRaw, Formatting.Indented);
                File.WriteAllText(Path.Combine(root, "characters\\schedules", character) + ".json", json);
                var schedule = new Schedule() { Character = character };
                foreach(var keyPair in scheduleRaw)
                {
                    schedule.ScheduledItems.Add(new Schedule.ScheduleItem()
                    {
                        Key = keyPair.Key
                    });
                    if (keyPair.Value.StartsWith("GOTO"))
                    {
                        schedule.ScheduledItems.Last().GotoKey = keyPair.Value.Substring(5);
                        continue;
                    }
                    else if (keyPair.Value.StartsWith("NOT"))
                    {

                    }
                    Console.WriteLine(keyPair.Key);
                    Console.WriteLine(keyPair.Value);
                }
                File.WriteAllText(Path.Combine(root, "characters\\schedules", character) + ".src.json", JsonConvert.SerializeObject(schedule, Formatting.Indented));
            }

            //content.Load<Dictionary<string,string>>("characters\\schedules\\leah").Dump();
        }
    }
    class Game1 : Microsoft.Xna.Framework.Game
    {
    }
    class Schedule
    {
        public class ScheduleItem
        {
            public class TargetLocationTime
            {
                public string Time { get; set; }
                public string Location { get; set; }
                public int X { get; set; }
                public int Y { get; set; }
                public int Direction { get; set; }

            }
            public class NotCondition
            {

            }
            public string Key { get; set; }
            public List<TargetLocationTime> TargetLocations { get; set; } = new List<TargetLocationTime>();
            public string GotoKey { get; set; }
            public NotCondition Condition { get; set; }
        }<commit_msg>Successfully parses out the times and at least doesn't fail with gotos etc<commit_after>﻿using Microsoft.Xna.Framework.Content;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ContentCompiler
{
    class Program
    {
        static void Main(string[] args)
        {
            Decompile();
        }
        static ContentManager SetupContentManager(string root)
        {

            var serviceContainer = new Microsoft.Xna.Framework.GameServiceContainer();
            var content = new Microsoft.Xna.Framework.Content.ContentManager(serviceContainer, root);
            var graphicsDevice = new Microsoft.Xna.Framework.GraphicsDeviceManager(new Game1());
            serviceContainer.AddService<Microsoft.Xna.Framework.Graphics.IGraphicsDeviceService>(graphicsDevice);
            return content;
        }
        static void Decompile()
        {
            var root = @"F:\steam\steamapps\common\Stardew Valley\Content";
            var content = SetupContentManager(root);

            var characters = Directory.EnumerateFiles(root + "\\characters\\schedules").Where(c=>Path.GetExtension(c)==".xnb").Select(c=>Path.GetFileNameWithoutExtension(c));
            foreach (var character in characters)
            {
                var scheduleRaw = content.Load<Dictionary<string, string>>("characters\\schedules\\" + character);
                var json = JsonConvert.SerializeObject(scheduleRaw, Formatting.Indented);
                File.WriteAllText(Path.Combine(root, "characters\\schedules", character) + ".json", json);
                var schedule = new Schedule() { Character = character };
                foreach(var keyPair in scheduleRaw)
                {
                    if (keyPair.Key.EndsWith("_Replacement"))
                        continue;
                    var value = keyPair.Value;
                    schedule.ScheduledItems.Add(new Schedule.ScheduleItem()
                    {
                        Key = keyPair.Key
                    });
                    if (value.StartsWith("NOT"))
                    {
                        value = string.Join("/", value.Split('/').Skip(1));
                    }
                    if (value.StartsWith("GOTO"))
                    {
                        schedule.ScheduledItems.Last().GotoKey = keyPair.Value.Substring(5);
                        continue;
                    }
                    var items = value.Split('/');
                    foreach(var item in items)
                    {
                        var pieces = item.Split(' ');
                        schedule.ScheduledItems.Last().TargetLocations.Add(new Schedule.ScheduleItem.TargetLocationTime()
                        {
                            Time = int.Parse(pieces[0])
                        });
                    }
                    Console.WriteLine(keyPair.Key);
                    Console.WriteLine(keyPair.Value);
                }
                File.WriteAllText(Path.Combine(root, "characters\\schedules", character) + ".src.json", JsonConvert.SerializeObject(schedule, Formatting.Indented));
            }

            //content.Load<Dictionary<string,string>>("characters\\schedules\\leah").Dump();
        }
    }
    class Game1 : Microsoft.Xna.Framework.Game
    {
    }
    class Schedule
    {
        public class ScheduleItem
        {
            public class TargetLocationTime
            {
                public int Time { get; set; }
                public string Location { get; set; }
                public int X { get; set; }
                public int Y { get; set; }
                public int Direction { get; set; }

            }
            public class NotCondition
            {

            }
            public string Key { get; set; }
            public List<TargetLocationTime> TargetLocations { get; set; } = new List<TargetLocationTime>();
            public string GotoKey { get; set; }
            public NotCondition Condition { get; set; }
        }
{'fraction_non_alphanumeric': 0.09920318725099601, 'fraction_numerical': 0.0010624169986719787, 'mean_word_length': 1.666784702549575, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '793583', 'n_tokens_mistral': 1840, 'n_tokens_neox': 1764, 'n_words': 376}