Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AllFiles iterator implementation and some small fixes #77

Merged
merged 5 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion SurrealEngine/Native/NActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,12 @@ void NActor::GetMapName(UObject* Self, const std::string& NameEnding, const std:
// Filter list to only those with the matching map type
for (const std::string& name : engine->packages->GetMaps())
{
if (name.size() >= NameEnding.size() && name.substr(0, NameEnding.size()) == NameEnding)
// Case insensitive prefix comparison because Unreal Deathmatch maps start with "Dm" instead of "DM"
#ifdef WIN32
if (name.size() >= NameEnding.size() && _stricmp(name.substr(0, NameEnding.size()).c_str(), NameEnding.c_str()) == 0)
#else
if (name.size() >= NameEnding.size() && strcasecmp(name.substr(0, NameEnding.size()).c_str(), NameEnding.c_str()) == 0)
#endif
maps.push_back(name);
}

Expand Down
11 changes: 11 additions & 0 deletions SurrealEngine/Native/NObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ void NObject::RegisterFunctions()
RegisterVMNativeFunc_3("Object", "XorXor_BoolBool", &NObject::XorXor_BoolBool, 131);
RegisterVMNativeFunc_3("Object", "Xor_IntInt", &NObject::Xor_IntInt, 157);

// Unreal Gold 227 exclusive functions
if (engine->LaunchInfo.gameExecutableName == "Unreal" && engine->LaunchInfo.engineVersion == 227)
{
RegisterVMNativeFunc_3("Object", "AllFiles", &NObject::AllFiles, 603);
}

// Package 61 stuff
if (engine->LaunchInfo.engineVersion <= 219)
{
Expand Down Expand Up @@ -276,6 +282,11 @@ void NObject::And_IntInt(int A, int B, int& ReturnValue)
ReturnValue = A & B;
}

void NObject::AllFiles(const std::string& FileExtension, const std::string& FilePrefix, std::string& outFileName)
{
Frame::CreatedIterator = std::make_unique<AllFilesIterator>(FileExtension, FilePrefix, outFileName);
}

void NObject::Asc(const std::string& S, int& ReturnValue)
{
ReturnValue = !S.empty() ? S.front() : '\0';
Expand Down
1 change: 1 addition & 0 deletions SurrealEngine/Native/NObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class NObject
static void Add_IntInt(int A, int B, int& ReturnValue);
static void Add_RotatorRotator(const Rotator& A, const Rotator& B, Rotator& ReturnValue);
static void Add_VectorVector(const vec3& A, const vec3& B, vec3& ReturnValue);
static void AllFiles(const std::string& FileExtension, const std::string& FilePrefix, std::string& outFileName);
static void AndAnd_BoolBool(bool A, BitfieldBool* B, BitfieldBool& ReturnValue);
static void And_IntInt(int A, int B, int& ReturnValue);
static void Asc(const std::string& S, int& ReturnValue);
Expand Down
6 changes: 3 additions & 3 deletions SurrealEngine/Package/PackageManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class PackageManager
public:
PackageManager(const GameLaunchInfo& launchInfo);

bool IsUnreal1() const { return launchInfo.gameName == "Unreal"; }
bool IsUnreal1() const { return launchInfo.gameExecutableName == "Unreal"; }
bool IsUnreal1_226() const { return IsUnreal1() && launchInfo.engineVersion == 226; }
bool IsUnreal1_227() const { return IsUnreal1() && launchInfo.engineVersion == 227; }
bool IsUnrealTournament() const { return launchInfo.gameName == "UnrealTournament"; }
bool IsUnrealTournament() const { return launchInfo.gameExecutableName == "UnrealTournament"; }
bool IsUnrealTournament_469() const { return IsUnrealTournament() && launchInfo.engineVersion == 469; }
bool IsDeusEx() const { return launchInfo.gameName == "DeusEx"; }
bool IsDeusEx() const { return launchInfo.gameExecutableName == "DeusEx"; }

int GetEngineVersion() const { return launchInfo.engineVersion; }
int GetEngineSubVersion() const { return launchInfo.engineSubVersion; }
Expand Down
3 changes: 2 additions & 1 deletion SurrealEngine/UObject/UActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ void UActor::SetOwner(UActor* newOwner)

void UActor::AddChildActor(UActor* actor)
{
ChildActors.push_back(actor);
if (actor)
ChildActors.push_back(actor);
}

void UActor::RemoveChildActor(UActor* actor)
Expand Down
33 changes: 33 additions & 0 deletions SurrealEngine/VM/Iterator.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

#include "Precomp.h"
#include "Iterator.h"
#include "File.h"
#include "Engine.h"
#include "Package/PackageManager.h"
#include "UObject/ULevel.h"
#include "UObject/UActor.h"
#include "Collision/OverlapCylinderLevel.h"
Expand All @@ -28,6 +30,37 @@ bool AllObjectsIterator::Next()

/////////////////////////////////////////////////////////////////////////////

AllFilesIterator::AllFilesIterator(const std::string& FileExtension, const std::string& FilePrefix, std::string& FileName) : FileExtension(FileExtension), FilePrefix(FilePrefix), FileName(FileName)
{
auto packageNames = engine->packages->GetPackageNames();

for (auto& packageName : packageNames)
{
auto package = engine->packages->GetPackage(packageName);

if ((FileExtension.empty() || FilePath::extension(package->GetPackageFilename()) == FileExtension) &&
(FilePrefix.empty() || package->GetPackageFilename().find(FilePrefix) != std::string::npos))
{
FoundFiles.push_back(packageName.ToString());
}
}

iterator = FoundFiles.begin();
}

bool AllFilesIterator::Next()
{
if (iterator == FoundFiles.end())
return false;

FileName = *iterator;
iterator++;

return true;
}

/////////////////////////////////////////////////////////////////////////////

BasedActorsIterator::BasedActorsIterator(UActor* Caller, UObject* BaseClass, UObject** Actor) : BaseClass(BaseClass), Actor(Actor)
{
for (UActor* levelActor : engine->Level->Actors)
Expand Down
16 changes: 16 additions & 0 deletions SurrealEngine/VM/Iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ class AllObjectsIterator : public Iterator
size_t index = 0;
};

// As seen on Unreal Gold 227
class AllFilesIterator : public Iterator
{
public:
// Iterates through all files of a type (Extensions are the usual Unreal Package extensions, or all files, if the FileExtension string is empty)
AllFilesIterator(const std::string& FileExtension, const std::string& FilePrefix, std::string& FileName);
bool Next() override;

private:
std::string FileExtension;
std::string FilePrefix;
std::string& FileName;
std::vector<std::string> FoundFiles;
std::vector<std::string>::iterator iterator;
};

class BasedActorsIterator : public Iterator
{
public:
Expand Down