Skip to content

Commit

Permalink
Use fake flags file for Starfield if none is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitalita committed Sep 29, 2023
1 parent 04c6cb4 commit 2a97ea3
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 65 deletions.
60 changes: 59 additions & 1 deletion Caprica/common/FakeScripts.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "FakeScripts.h"
#include "common/GameID.h"
#include <common/GameID.h>

namespace caprica {
constexpr const char* FAKE_SKYRIM_SCRIPTOBJECT_SCRIPT =
Expand Down Expand Up @@ -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<identifier_ref> FAKE_SCRIPTS = {
{"fake://skyrim/__ScriptObject.psc", FAKE_SKYRIM_SCRIPTOBJECT_SCRIPT },
{ "fake://skyrim/DLC1SCWispWallScript.psc", MISSING_DLC1SCWispWallScript_SKYRIM},
Expand All @@ -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;
}


}
7 changes: 5 additions & 2 deletions Caprica/common/FakeScripts.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#pragma once
#include "CaselessStringComparer.h"
#include "GameID.h"
#include <common/CaselessStringComparer.h>
#include <common/GameID.h>


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);
};
}
15 changes: 15 additions & 0 deletions Caprica/common/parser/CapricaUserFlagsLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <unordered_map>
#include <utility>

#include <common/FakeScripts.h>
#include <common/CapricaConfig.h>
#include <common/CaselessStringComparer.h>

Expand Down Expand Up @@ -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.
}

}}
13 changes: 6 additions & 7 deletions Caprica/common/parser/CapricaUserFlagsLexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
};
Expand Down
6 changes: 6 additions & 0 deletions Caprica/main_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
55 changes: 0 additions & 55 deletions test/Starfield_Papyrus_Flags.flg

This file was deleted.

0 comments on commit 2a97ea3

Please sign in to comment.