Skip to content

Commit

Permalink
The start of a long and arduous road to refactor this mess
Browse files Browse the repository at this point in the history
  • Loading branch information
alphanin9 committed Feb 25, 2025
1 parent 201d6f1 commit 0f72584
Show file tree
Hide file tree
Showing 49 changed files with 185 additions and 135 deletions.
2 changes: 1 addition & 1 deletion config/projectTemplate.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

namespace build
{
constexpr auto c_version = semver::from_string_noexcept("${VERSION}").value();
constexpr auto ModVersion = semver::from_string_noexcept("${VERSION}").value();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <RED4ext/RED4ext.hpp>
#include <RedLib.hpp>

#include <redscript_api/NewGamePlusSystem.hpp>
#include <GameSystem/NewGamePlusSystem.hpp>

#include <RED4ext/Scripting/Natives/Generated/gsm/MainQuest.hpp>
#include <RED4ext/Scripting/Natives/gameGameSessionDesc.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <RED4ext/Scripting/Natives/Generated/cp/PlayerSystem.hpp>
#include <RED4ext/Scripting/Natives/Generated/game/ui/CharacterCustomizationState.hpp>
#include <RED4ext/Scripting/Natives/Generated/quest/QuestsSystem.hpp>
#include <redscript_api/definitions/playerSaveData.hpp>
#include <util/settings/settingsAccessor.hpp>
#include <GameSystem/Definitions/PlayerSaveData.hpp>
#include <Util/Settings/SettingsAccessor.hpp>

namespace mod
{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <RED4ext/RED4ext.hpp>
#include <RedLib.hpp>

#include <parsing/definitions/nodeParsers/stats/statsSystemNode.hpp>
#include <Parsing/Definitions/NodeParsers/Stats/StatsSystemNode.hpp>

// Bits that need to be passed around
struct ResultContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ StatsSystemReader::StatsSystemResults::StatsSystemResults(ResultContext& aContex

if (settings::GetModSettings().m_clampPlayerLevel)
{
constexpr auto c_ep1MaxLevel = 50.f;
constexpr auto c_nonEp1MaxLevel = 40.f;
constexpr auto EP1MaxLevel = 50.f;
constexpr auto NonEp1MaxLevel = 40.f;

const auto gameEngine = CGameEngine::Get();

usedValue = std::min(usedValue, gameEngine->isEP1 ? c_ep1MaxLevel : c_nonEp1MaxLevel);
usedValue = std::min(usedValue, gameEngine->isEP1 ? EP1MaxLevel : NonEp1MaxLevel);
}

m_level = usedValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "playerSaveData.hpp"
#include "../dataReaders/resultContext.hpp"
#include "PlayerSaveData.hpp"

#include <parsing/definitions/nodeParsers/persistency/persistencySystemNode.hpp>
#include <parsing/definitions/nodeParsers/scriptable/scriptableContainerNodeV2.hpp>
#include <parsing/definitions/nodeParsers/stats/statsSystemNode.hpp>
#include <GameSystem/DataReaders/ResultContext.hpp>
#include <Parsing/Definitions/NodeParsers/Persistency/PersistencySystemNode.hpp>
#include <Parsing/Definitions/NodeParsers/Scriptable/ScriptableContainerNodeV2.hpp>
#include <Parsing/Definitions/NodeParsers/Stats/StatsSystemNode.hpp>

using namespace Red;

Expand Down
6 changes: 3 additions & 3 deletions src/filesystem/SaveFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

#include "SaveFS.hpp"

#include <context/context.hpp>
#include <Context/Context.hpp>

#include <Shared/RTTI/PropertyAccessor.hpp>
#include <Shared/Raw/FileSystem/FileSystem.hpp>
#include <Shared/Raw/Package/ScriptableSystemsPackage.hpp>
#include <Shared/Raw/Save/Save.hpp>
#include <util/settings/settingsAccessor.hpp>
#include <Util/Settings/SettingsAccessor.hpp>

using namespace Red;

Expand Down Expand Up @@ -600,7 +600,7 @@ bool IsValidForNewGamePlus(const CString& aSaveFullPath, uint64_t& aPlaythroughH
PluginContext::DebugLog("[IsValidForNewGamePlus {}] Is pre-replay PONR save", aSaveFullPath.c_str());
return false;
}

aPlaythroughHash = FNV1a64(metadata.playthroughID.c_str());

if (std::find(c_generatedPostPointOfNoReturnObjectives.begin(), c_generatedPostPointOfNoReturnObjectives.end(),
Expand Down
2 changes: 1 addition & 1 deletion src/hooking/hooking.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <RED4ext/RED4ext.hpp>
#include <RedLib.hpp>

#include <context/context.hpp>
#include <Context/Context.hpp>

#include <Shared/Hooks/HookManager.hpp>
#include <Shared/Raw/Telemetry/Telemetry.hpp>
Expand Down
14 changes: 7 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include <ArchiveXL.hpp>
#include <TweakXL.hpp>

#include <context/context.hpp>
#include <Context/Context.hpp>

#include <hooking/hooking.hpp>
#include <util/migration/migration.hpp>
#include <Hooking/Hooking.hpp>
#include <Util/Migration/Migration.hpp>

#include <config/projectTemplate.hpp>
#include <Config/ProjectTemplate.hpp>

#include <Shared/Raw/Assert/AssertionFailed.hpp>

Expand Down Expand Up @@ -86,9 +86,9 @@ RED4EXT_C_EXPORT void RED4EXT_CALL Query(PluginInfo* aInfo)
{
aInfo->name = L"New Game+";
aInfo->author = L"not_alphanine";
aInfo->version = RED4EXT_SEMVER_EX(static_cast<std::uint8_t>(build::c_version.major),
static_cast<std::uint8_t>(build::c_version.minor),
static_cast<std::uint8_t>(build::c_version.patch),
aInfo->version = RED4EXT_SEMVER_EX(static_cast<std::uint8_t>(build::ModVersion.major),
static_cast<std::uint8_t>(build::ModVersion.minor),
static_cast<std::uint8_t>(build::ModVersion.patch),
RED4EXT_V0_SEMVER_PRERELEASE_TYPE_NONE, 0); // Set your version here.
aInfo->runtime = RED4EXT_RUNTIME_INDEPENDENT;
aInfo->sdk = RED4EXT_SDK_LATEST;
Expand Down
2 changes: 1 addition & 1 deletion src/parsing/New/Nodes/ScriptableSystemsContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bool ScriptableSystemsContainerNode::OnRead(Save::Stream::LoadStream& aStream) n

// When you're too lazy to go and make a move ctor xD
// Evil code

// TODO: make operator, get it to R4e SDK
std::copy_n(reinterpret_cast<char*>(&buffer), sizeof(RawBuffer), reinterpret_cast<char*>(&m_buffer));
std::fill_n(reinterpret_cast<char*>(&buffer), sizeof(RawBuffer), 0);

Expand Down
6 changes: 3 additions & 3 deletions src/parsing/definitions/compression/compressionHeader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "../../cursorDef.hpp"

namespace compression {
constexpr auto COMPRESSION_HEADER_MAGIC = 0x434C5A46u;
constexpr auto COMPRESSION_BLOCK_MAGIC = 0x584C5A34u;
constexpr auto CompressionHeaderMagic = 0x434C5A46u;
constexpr auto CompressionBlockMagic = 0x584C5A34u;

struct DataChunkInfo {
int offset;
Expand All @@ -33,7 +33,7 @@ namespace compression {
static CompressionHeader fromCursor(FileCursor& cursor) {
const auto compressionHeaderBasePosition = cursor.offset;

if (cursor.readUInt() != COMPRESSION_HEADER_MAGIC) {
if (cursor.readUInt() != CompressionHeaderMagic) {
// Should probably throw an exception here
return {};
}
Expand Down
48 changes: 25 additions & 23 deletions src/parsing/definitions/fileInfo.hpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
#pragma once
#include <Parsing/CursorDef.hpp>

#include "../cursorDef.hpp"
namespace modsave
{
constexpr auto FILE_MAGIC = 0x43534156; // CSAV
constexpr auto FILE_DONE = 0x444F4E45; // DONE
constexpr auto FILE_NODE = 0x4e4f4445; // NODE

namespace modsave {
constexpr auto FILE_MAGIC = 0x43534156; // CSAV
constexpr auto FILE_DONE = 0x444F4E45; // DONE
constexpr auto FILE_NODE = 0x4e4f4445; // NODE
struct SaveHeader
{
std::uint32_t saveVersion{};
std::uint32_t gameVersion{};
std::wstring gameDefinition{};
std::uint64_t timeStamp{};
std::uint32_t archiveVersion{};

struct SaveHeader {
std::uint32_t saveVersion{};
std::uint32_t gameVersion{};
std::wstring gameDefinition{};
std::uint64_t timeStamp{};
std::uint32_t archiveVersion{};
static SaveHeader fromCursor(FileCursor& fileCursor)
{
SaveHeader header{};
header.saveVersion = fileCursor.readUInt();
header.gameVersion = fileCursor.readUInt();
header.gameDefinition = fileCursor.readLengthPrefixedString();
header.timeStamp = fileCursor.readUInt64();
header.archiveVersion = fileCursor.readUInt();

static SaveHeader fromCursor(FileCursor& fileCursor) {
SaveHeader header{};
header.saveVersion = fileCursor.readUInt();
header.gameVersion = fileCursor.readUInt();
header.gameDefinition = fileCursor.readLengthPrefixedString();
header.timeStamp = fileCursor.readUInt64();
header.archiveVersion = fileCursor.readUInt();

return header;
}
};
}
return header;
}
};
} // namespace modsave
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <cassert>
#include <vector>

#include "../interfaceNodeData.hpp"
#include "helpers/nativePersistencyReader.hpp"
#include "Helpers/NativePersistencyReader.hpp"
#include <Parsing/Definitions/NodeParsers/InterfaceNodeData.hpp>

#include <RED4ext/Scripting/Natives/Generated/vehicle/GarageComponentPS.hpp>

Expand Down Expand Up @@ -75,7 +75,7 @@ class PersistencySystemNode : public NodeDataInterface
// Could just skip ahead...

m_unk1 = aCursor.readUInt();

persistency::native::NativePersistencyReader reader{};

const auto itemCount = aCursor.readInt();
Expand Down Expand Up @@ -144,7 +144,7 @@ class PersistencySystemNode : public NodeDataInterface

if (chunkIt == m_instances.end())
{
PluginContext::Error(std::format("Failed to find class {} in PersistencySystem2", aChunkName));
PluginContext::Error("Failed to find class {} in PersistencySystem2", aChunkName);
return nullptr;
}

Expand All @@ -162,4 +162,4 @@ class PersistencySystemNode : public NodeDataInterface
return chunkIt != m_instances.end();
}
};
}
} // namespace modsave
11 changes: 4 additions & 7 deletions src/parsing/definitions/nodeParsers/quest/factsDBNode.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#include <format>
#include "FactsDBNode.hpp"

#include "factsDBNode.hpp"

#include "../../nodeEntry.hpp"
#include "../parserHelper.hpp"

#include <context/context.hpp>
#include <Context/Context.hpp>
#include <Parsing/Definitions/NodeEntry.hpp>
#include <Parsing/Definitions/NodeParsers/ParserHelper.hpp>

namespace modsave
{
Expand Down
4 changes: 1 addition & 3 deletions src/parsing/definitions/nodeParsers/quest/factsDBNode.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once
#include <unordered_map>

#include "../interfaceNodeData.hpp"
#include <Parsing/Definitions/NodeParsers/DefaultNodeData.hpp>
namespace modsave
{
class FactsTableNode : public NodeDataInterface
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once

#include <RED4ext/RED4ext.hpp>
#include <RedLib.hpp>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "scriptableContainerNodeV2.hpp"
#include "ScriptableContainerNodeV2.hpp"

using namespace Red;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
#include <RED4ext/Package.hpp>
#include <RedLib.hpp>

#include "../defaultNodeData.hpp"

#include "../../package/packageReader.hpp"
#include <Parsing/Definitions/NodeParsers/DefaultNodeData.hpp>
#include <Parsing/Definitions/Package/PackageReader.hpp>

namespace modsave
{
Expand Down
6 changes: 3 additions & 3 deletions src/parsing/definitions/nodeParsers/stats/statsSystemNode.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Dumb project structure strikes again...
#include <context/context.hpp>
#include <Context/Context.hpp>

#include <RED4ext/Scripting/Natives/Generated/game/StatsStateMapStructure.hpp>

Expand All @@ -8,8 +8,8 @@
#include <RED4ext/Scripting/Natives/Generated/game/CombinedStatModifierData_Deprecated.hpp>
#include <RED4ext/Scripting/Natives/Generated/game/CurveStatModifierData_Deprecated.hpp>

#include "statsSystemNode.hpp"
#include "../../package/packageReader.hpp"
#include "StatsSystemNode.hpp"
#include <Parsing/Definitions/Package/PackageReader.hpp>

using namespace Red;

Expand Down
6 changes: 3 additions & 3 deletions src/parsing/definitions/nodeParsers/stats/statsSystemNode.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "../interfaceNodeData.hpp"
#include "../../nodeEntry.hpp"
#include "../../package/packageReader.hpp"
#include <Parsing/Definitions/NodeEntry.hpp>
#include <Parsing/Definitions/NodeParsers/InterfaceNodeData.hpp>
#include <Parsing/Definitions/Package/PackageReader.hpp>

#include <RED4ext/Scripting/Natives/Generated/game/SavedStatsData.hpp>
#include <RED4ext/Scripting/Natives/Generated/game/StatModifierData_Deprecated.hpp>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "wardrobeSystemNode.hpp"
#include "../inventory/inventoryNode.hpp"
#include "WardrobeSystemNode.hpp"
#include <Parsing/Definitions/NodeParsers/Inventory/InventoryNode.hpp>

using namespace Red;

Expand Down
5 changes: 3 additions & 2 deletions src/parsing/definitions/package/packageReader.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "packageReader.hpp"
#include "PackageReader.hpp"

#include <RED4ext/Scripting/Natives/Generated/game/StatIDType.hpp>
#include <RED4ext/Scripting/Natives/Generated/game/data/StatType.hpp>

#include <chrono>
#include <unordered_map>

#include <context/context.hpp>
#include <Context/Context.hpp>

// TODO: throw this out, replace with game impl
namespace package
{
bool Package::ResolveEnumValue(Red::CEnum* aEnum, Red::CName aName, std::int64_t& aRet) noexcept
Expand Down
6 changes: 2 additions & 4 deletions src/parsing/definitions/package/packageReader.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#pragma once
// Later...
#include "../../cursorDef.hpp"
#include <Parsing/CursorDef.hpp>

#include <RED4ext/RED4ext.hpp>
#include <RED4ext/Package.hpp>
#include <RedLib.hpp>

#include "../rttiHelpers/rttiValueReaderNative.hpp"
#include <Parsing/Definitions/RTTIHelpers/RTTIValueReaderNative.hpp>

#include <unordered_map>

Expand Down
Loading

0 comments on commit 0f72584

Please sign in to comment.