/* * V-Gears * Copyright (C) 2022 V-Gears Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #pragma once #include #include "decompiler/Decompiler.h" #include "FieldScriptFormatter.h" /** * Decompiler for field maps. */ class FieldDecompiler: public Decompiler{ public: /** * A line. */ struct Line{ /** * Name of the line entity. */ std::string name; /** * First point of the line. */ std::vector point_a; /** * Second point of the line. */ std::vector point_b; }; /** * An entity. */ struct FieldEntity{ /** * Character identifier of the entity. */ uint char_id; /** * Index of the entity in the field. */ uint index; /** * Name of the entity. */ std::string name; }; /** * The field decompiled script. */ struct DecompiledScript{ /** * The LUA script for the field. */ std::string luaScript; /** * The field entities. * * Lines are not included. */ std::vector entities; /** * Lines in the field. */ std::vector lines; }; /** * Retrieves the scale factor of a field. * * @param[in] script_bytes Vector of raw byte data that makes up * the script. * @return The scale fctor. */ static float ScaleFactor(const std::vector& script_bytes); /** * Decompiles a field script. * * @param[in] script_name Name of the script to be converted, * should match file name. * @param[in] script_bytes Vector of raw byte data that makes up * the script. * @param[in] formatter Formatter used to rename variables, drop * functions... * @param[in] text_after Raw text that is added at to the end of * the decompiled output. * @param[in] text_before Raw text that is added at to the start of * the decompiled output. * @return A string with the decompiled script. * @throws DecompilerException on failure. */ static DecompiledScript Decompile( std::string script_name, const std::vector& script_bytes, FieldScriptFormatter& formatter, std::string text_after = "", std::string text_before = "" ); };