diff --git a/Caprica/common/FakeScripts.cpp b/Caprica/common/FakeScripts.cpp index 41bde96..1f2ce9d 100644 --- a/Caprica/common/FakeScripts.cpp +++ b/Caprica/common/FakeScripts.cpp @@ -1,5 +1,5 @@ #include "FakeScripts.h" -#include "common/GameID.h" +#include namespace caprica { constexpr const char* FAKE_SKYRIM_SCRIPTOBJECT_SCRIPT = @@ -66,6 +66,57 @@ Function DropWall(ObjectReference WallEffect) EndFunction )"; +constexpr const char* STARFIELD_FAKE_FLAGS_FILE = +R"(// Starfield flags file, by NikitaLita +// This file is conjecture, based on the userflags set by the base starfield game scripts. + +// Flag hides the script or property from the game editor + Flag Hidden 0 + { + Script + Property + StructVar + } + +// Flag on an object designates it as the script the condition system will look at +// Flag on a variable allows the script variable to be examined by the condition system + Flag Conditional 1 + { + Script + Variable + } + +// Flags the specified script as a default script, for filtering in the editor + Flag Default 2 + { + Script + } + +// Flags this group as collapsed on the reference in the editor + Flag CollapsedOnRef 3 + { + Group + } + +// Flags this group as collapsed on the base object in the editor + Flag CollapsedOnBase 4 + { + Group + } + +// Flags this group as collapsed (on both ref and base) in the editor + Flag Collapsed CollapsedOnRef & CollapsedOnBase + +// Flags a property as mandatory - in other words, will spit out a warning in +// the editor if it isn't given a value + Flag Mandatory 5 + { + Property + } +)"; + + + static const caseless_unordered_identifier_ref_map FAKE_SCRIPTS = { {"fake://skyrim/__ScriptObject.psc", FAKE_SKYRIM_SCRIPTOBJECT_SCRIPT }, { "fake://skyrim/DLC1SCWispWallScript.psc", MISSING_DLC1SCWispWallScript_SKYRIM}, @@ -88,4 +139,11 @@ size_t FakeScripts::getSizeOfFakeScript(const identifier_ref& name, GameID game) return it->second.size(); } +identifier_ref FakeScripts::getFakeFlagsFile(GameID game) { + if (game != GameID::Starfield) + return {}; + return STARFIELD_FAKE_FLAGS_FILE; +} + + } diff --git a/Caprica/common/FakeScripts.h b/Caprica/common/FakeScripts.h index 36d91b8..717846b 100644 --- a/Caprica/common/FakeScripts.h +++ b/Caprica/common/FakeScripts.h @@ -1,10 +1,13 @@ #pragma once -#include "CaselessStringComparer.h" -#include "GameID.h" +#include +#include + namespace caprica { +struct CapricaUserFlagsDefinition; struct FakeScripts { static identifier_ref getFakeScript(const identifier_ref& name, GameID game); static size_t getSizeOfFakeScript(const identifier_ref& name, GameID game); + static identifier_ref getFakeFlagsFile(GameID game); }; } diff --git a/Caprica/common/parser/CapricaUserFlagsLexer.cpp b/Caprica/common/parser/CapricaUserFlagsLexer.cpp index 24accb2..e1a43e8 100644 --- a/Caprica/common/parser/CapricaUserFlagsLexer.cpp +++ b/Caprica/common/parser/CapricaUserFlagsLexer.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -207,5 +208,19 @@ void CapricaUserFlagsLexer::consume() { reportingContext.fatal(baseLoc, "Unexpected character '{}'!", (char)c); } } +CapricaUserFlagsLexer::CapricaUserFlagsLexer(CapricaReportingContext& repCtx, const std::string& file) + : filename(file), cur(TokenType::Unknown), reportingContext(repCtx) { + if (filename.starts_with("fake://")){ + strmString.str(FakeScripts::getFakeFlagsFile(conf::Papyrus::game).to_string()); + strm = &strmString; + } else { + strmFile.open(filename, std::ifstream::binary); + if (!strmFile.is_open()) { + CapricaReportingContext::logicalFatal("Unable to open file '%s'!", filename.c_str()); + } + strm = &strmFile; + } + consume(); // set the first token. +} }} diff --git a/Caprica/common/parser/CapricaUserFlagsLexer.h b/Caprica/common/parser/CapricaUserFlagsLexer.h index 1aecfa6..c15c1d4 100644 --- a/Caprica/common/parser/CapricaUserFlagsLexer.h +++ b/Caprica/common/parser/CapricaUserFlagsLexer.h @@ -62,10 +62,7 @@ struct CapricaUserFlagsLexer { static const std::string prettyTokenType(TokenType tp); }; - explicit CapricaUserFlagsLexer(CapricaReportingContext& repCtx, const std::string& file) - : filename(file), strm(file, std::ifstream::binary), cur(TokenType::Unknown), reportingContext(repCtx) { - consume(); // set the first token. - } + explicit CapricaUserFlagsLexer(CapricaReportingContext& repCtx, const std::string& file); CapricaUserFlagsLexer(const CapricaUserFlagsLexer&) = delete; ~CapricaUserFlagsLexer() = default; @@ -77,14 +74,16 @@ struct CapricaUserFlagsLexer { void consume(); private: - std::ifstream strm; + std::istream * strm; + std::istringstream strmString; + std::ifstream strmFile; CapricaFileLocation location {}; int getChar() { location.startOffset++; - return strm.get(); + return strm->get(); } - int peekChar() { return strm.peek(); } + int peekChar() { return strm->peek(); } void setTok(TokenType tp, CapricaFileLocation loc); void setTok(Token& tok); }; diff --git a/Caprica/main_options.cpp b/Caprica/main_options.cpp index a147daa..a15e439 100644 --- a/Caprica/main_options.cpp +++ b/Caprica/main_options.cpp @@ -537,8 +537,14 @@ bool parseCommandLineArguments(int argc, char* argv[], caprica::CapricaJobManage } parseUserFlags(std::move(flagsPath)); + } else { + if (conf::Papyrus::game == GameID::Starfield){ + std::cout << "No flags specified, Using default Starfield flags file." << std::endl; + parseUserFlags("fake://Starfield/Starfield_Papyrus_Flags.flg"); + } } + if (!handleImports(conf::Papyrus::importDirectories, jobManager)) { std::cout << "Import failed!" << std::endl; return false; diff --git a/test/Starfield_Papyrus_Flags.flg b/test/Starfield_Papyrus_Flags.flg deleted file mode 100644 index fab8516..0000000 --- a/test/Starfield_Papyrus_Flags.flg +++ /dev/null @@ -1,55 +0,0 @@ -/* - Format is as follows (whitespace is completely ignored, index must be between 0 and 31 inclusive): - Flag // flag is allowed on all types - or: - Flag { } // flag is allowed only on the specified types - or: - Flag (& )+ - // flag made up of a combination of child flags. This flag will NOT appear in the object, only the ones it is made up of -*/ - -// List of flags for Starfield - DO NOT EDIT - -// Flag hides the script or property from the game editor -Flag Hidden 0 -{ - Script - Property - StructVar -} - -// Flag on an object designates it as the script the condition system will look at -// Flag on a variable allows the script variable to be examined by the condition system -Flag Conditional 1 -{ - Script - Variable -} - -// Flags the specified script as a default script, for filtering in the editor -Flag Default 2 -{ - Script -} - -// Flags this group as collapsed on the reference in the editor -Flag CollapsedOnRef 3 -{ - Group -} - -// Flags this group as collapsed on the base object in the editor -Flag CollapsedOnBase 4 -{ - Group -} - -// Flags this group as collapsed (on both ref and base) in the editor -Flag Collapsed CollapsedOnRef & CollapsedOnBase - -// Flags a property as mandatory - in other words, will spit out a warning in -// the editor if it isn't given a value -Flag Mandatory 5 -{ - Property -} \ No newline at end of file