<commit_before>﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ZActor.OActors;
using RHelper;

namespace mzxrules.OcaLib.SceneRoom
{
    public static class SceneRoomReader
    {
        public static Scene InitializeScene(int number, RomFile file)
        {
            BinaryReader br;
            Scene scene = null;

            if (file == null)
                return scene;

            scene = new Scene(file.Version.Game, number, file.Record.VirtualAddress);
            br = new BinaryReader(file);

            //if (LocalFileTable.Version == ORom.Build.N0
            //    && number == 6)
            //    SpiritHack.LoadSpiritSceneHeader(br, scene);
            //else
                LoadISceneRoomHeader(br, scene);
            return scene;
        }

        public static Scene InitializeScene(int number, BinaryReader br, Game game)
        {
            Scene scene;
            scene = new Scene(game, number, new FileAddress());
            LoadISceneRoomHeader(br, scene);
            return scene;
        }

        public static Room InitializeRoom(RomFile file)
        {
            BinaryReader br;
            Room newRoom = new Room(file.Version.Game, file.Record.VirtualAddress);

            br = new BinaryReader(file);
            LoadISceneRoomHeader(br, newRoom);
            return newRoom;
        }

        //public static Room LoadSpiritRoom(FileAddress addr, int roomNo)
        //{
        //    BinaryReader br;
        //    Room item = new Room(LocalFileTable.Version.Game, addr);

        //    br = new BinaryReader(LocalFileTable.GetFile(item.VirtualAddress.Start));
        //    SpiritHack.LoadSpiritRoomHeader(br, item, roomNo);
        //    return item;
        //}
        
        #region InitializeMembers
        
        private static void LoadISceneRoomHeader(BinaryReader br, ISceneRoomHeader item)
        {
            SceneHeader header;
            header = item.Header;

            //Load the root header
            header.Load(br, 0);
            header.InitializeAssets(br);

            if (header.HasAlternateHeaders())
            {
                for (int i = 0; i < header.Alternate.HeaderList.Count; i++)
                {
                    if (header.Alternate.HeaderList[i] != null)
                    {
                        header.Alternate.HeaderList[i].Load(br, header.Alternate.HeaderOffsetsList[i]);
                        header.Alternate.HeaderList[i].InitializeAssets(br);
                    }
                }
            }
        }

        #endregion

        public static string ReadCutscene(Rom rom, long address)
        {
            FileRecord addr;
            Cutscenes.Cutscene cs;

            addr = rom.Files.GetFileStart(address);
            if (addr == null)
                return "Input address does not point within a file.";
            var s = (Stream)rom.Files.GetFile(addr.VirtualAddress);
            s.Position = addr.GetRelativeAddress(address);
            cs = new Cutscenes.Cutscene(s);

            return cs.PrintCutsceneByCommandOrder();
        }

        public static string ReadScene(Scene scene)
        {
            StringBuilder result = new StringBuilder();

            if (scene == null)
                return "NULL";

            result.AppendFormat("Scene at {0:X8}", scene.VirtualAddress.Start);
            result.AppendLine();
            result.Append(ReadHeader(scene.Header));

            return result.ToString();
        }
<commit_msg>Removed cutscene reading from SceneRoomReader<commit_after>﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ZActor.OActors;
using mzxrules.OcaLib.Helper;

namespace mzxrules.OcaLib.SceneRoom
{
    /// <summary>
    /// A gross class that was written to initially manage VerboseOcarina's core functionality
    /// </summary>
    public static class SceneRoomReader
    {
        public static Scene InitializeScene(int number, RomFile file)
        {
            BinaryReader br;
            Scene scene = null;

            if (file == null)
                return scene;

            scene = new Scene(file.Version.Game, number, file.Record.VirtualAddress);
            br = new BinaryReader(file);

            //if (LocalFileTable.Version == ORom.Build.N0
            //    && number == 6)
            //    SpiritHack.LoadSpiritSceneHeader(br, scene);
            //else
                LoadISceneRoomHeader(br, scene);
            return scene;
        }

        public static Scene InitializeScene(int number, BinaryReader br, Game game)
        {
            Scene scene;
            scene = new Scene(game, number, new FileAddress());
            LoadISceneRoomHeader(br, scene);
            return scene;
        }

        public static Room InitializeRoom(RomFile file)
        {
            BinaryReader br;
            Room newRoom = new Room(file.Version.Game, file.Record.VirtualAddress);

            br = new BinaryReader(file);
            LoadISceneRoomHeader(br, newRoom);
            return newRoom;
        }

        //public static Room LoadSpiritRoom(FileAddress addr, int roomNo)
        //{
        //    BinaryReader br;
        //    Room item = new Room(LocalFileTable.Version.Game, addr);

        //    br = new BinaryReader(LocalFileTable.GetFile(item.VirtualAddress.Start));
        //    SpiritHack.LoadSpiritRoomHeader(br, item, roomNo);
        //    return item;
        //}
        
        #region InitializeMembers
        
        private static void LoadISceneRoomHeader(BinaryReader br, ISceneRoomHeader item)
        {
            SceneHeader header;
            header = item.Header;

            //Load the root header
            header.Load(br, 0);
            header.InitializeAssets(br);

            if (header.HasAlternateHeaders())
            {
                for (int i = 0; i < header.Alternate.HeaderList.Count; i++)
                {
                    if (header.Alternate.HeaderList[i] != null)
                    {
                        header.Alternate.HeaderList[i].Load(br, header.Alternate.HeaderOffsetsList[i]);
                        header.Alternate.HeaderList[i].InitializeAssets(br);
                    }
                }
            }
        }

        #endregion

        public static bool TryGetCutscene(Rom rom, long address, out Cutscenes.Cutscene cutscene)
        {
            FileRecord addr;
            cutscene = null;

            addr = rom.Files.GetFileStart(address);
            if (addr == null)
                return false;
            var s = (Stream)rom.Files.GetFile(addr.VirtualAddress);
            s.Position = addr.GetRelativeAddress(address);
            cutscene = new Cutscenes.Cutscene(s);
            return true;
        }

        public static string ReadScene(Scene scene)
        {
            StringBuilder result = new StringBuilder();

            if (scene == null)
                return "NULL";

            result.AppendFormat("Scene at {0:X8}", scene.VirtualAddress.Start);
            result.AppendLine();
            result.Append(ReadHeader(scene.Header));

            return result.ToString();
        }

{'fraction_non_alphanumeric': 0.09161469161469162, 'fraction_numerical': 0.0016632016632016633, 'mean_word_length': 1.6335766423357665, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '4210502', 'n_tokens_mistral': 1919, 'n_tokens_neox': 1821, 'n_words': 434}