Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Implemented new spline system
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-90 committed Nov 13, 2022
1 parent f3c96b3 commit 65117bb
Show file tree
Hide file tree
Showing 112 changed files with 2,928 additions and 181 deletions.
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rrox/api",
"version": "1.0.3",
"version": "1.1.0",
"description": "RailroadsOnline Extended API",
"license": "MIT",
"author": "_tom()",
Expand Down
9 changes: 8 additions & 1 deletion packages/api/src/controller/actions/getStruct.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IEnum, IStruct, IFunction } from "../struct";
import { IEnum, IStruct, IFunction, StructInfo } from "../struct";

/**
* The Get Struct Action allows you to retrieve metadata from game structs.
Expand All @@ -23,6 +23,13 @@ export interface IGetStructAction {
*/
getFunction( name: string ): Promise<IFunction | null>;

/**
* Retrieves an empty struct info metadata object.
*
* @param name Name of the struct to retrieve it for.
*/
getInstance<T extends object = any>( name: string ): StructInfo<T>;

/**
* Retrieves the full list of structs defined in the game.
* (Warning! This function will take some time and return a large array)
Expand Down
15 changes: 13 additions & 2 deletions packages/api/src/controller/actions/query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IQuery, QueryBuilderFunction } from "../query";
import { StructConstructor } from "../struct";
import { MultiLinkedStructRef, StructConstructor } from "../struct";
import { LinkedStructRef } from "../struct";

/**
Expand Down Expand Up @@ -31,6 +31,7 @@ export interface IQueryAction {
*
* @param query Prepared query
* @param base Input struct from the query
* @param timeout Query timeout in msec (default = 20000)
* @returns Query result (or null if it failed)
*
* @example
Expand All @@ -39,7 +40,7 @@ export interface IQueryAction {
* playerReference
* );
*/
query<T extends object>( query: IQuery<T>, base: T ): Promise<T | null>;
query<T extends object>( query: IQuery<T>, base: T, timeout?: number ): Promise<T | null>;

/**
* Retrieves a reference to the particular struct class.
Expand All @@ -51,6 +52,16 @@ export interface IQueryAction {
*/
getReference<T extends object>( base: StructConstructor<T> ): Promise<LinkedStructRef<T> | null>;

/**
* Retrieves a reference to multiple struct class.
* Using this reference, it is possible to retrieve all existing instances in game, or get a static reference to the class.
* For more information, see the documentation: {@link https://rrox-docs.tom90.nl/basics/querying#querying-globally}
*
* @param baseConstructors Base classes to get the multi reference for
* @returns Reference to multiple structs (or null if failed)
*/
getMultiReference<T extends object>( baseConstructors: StructConstructor<T>[] ): Promise<MultiLinkedStructRef<T> | null>;

/**
* Stores any changes made to the instance in game memory.
* This method does not store any changes made in sub-objects.
Expand Down
18 changes: 18 additions & 0 deletions packages/api/src/controller/struct/info.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { StructConstructor } from ".";
import { IStruct } from "./struct";

export interface StructInfo<T extends object> {
/**
* Instance of a class to apply the struct builder to
Expand All @@ -8,4 +11,19 @@ export interface StructInfo<T extends object> {
* Retrieves the name of the struct, if available.
*/
getName(): string | null;

/**
* Get metadata belonging to this struct
*/
getStruct(): Promise<IStruct | null>;

/**
* Returns a fresh copy of this StructInstance
*/
clone(): StructInfo<T>;

/**
* Returns a fresh copy of this StructInstance
*/
clone<C extends object>( base: StructConstructor<C> ): StructInfo<C>;
}
20 changes: 20 additions & 0 deletions packages/api/src/controller/struct/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,24 @@ export interface LinkedStructRef<S extends object> extends StructRef<S> {
* @param base JavaScript class to use for the StructRef
*/
getStatic( base: StructConstructor<S> ): Promise<S | null>;
}

/**
* Reference to multiple static classes.
* Can be used to more efficiently query a lot of different types of structs simultaniously.
*/
export interface MultiLinkedStructRef<S extends object> {
/**
* Retrieves the underlying structs of this multi struct
*/
getStructs(): LinkedStructRef<S>[];

/**
* Retrieve a list of all instantiations of the classes beloning to this multi ref.
* For effiency, it is possible to limit the number of instances to get.
*
* @param count Maximum number of instances to get
* @param deep Whether or not to check super classes
*/
getInstances( count?: number, deep?: boolean ): Promise<S[] | null>;
}
2 changes: 1 addition & 1 deletion packages/base-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"copyfiles": "^2.4.1"
},
"dependencies": {
"@rrox/api": "^1.0.3",
"@rrox/api": "^1.1.0",
"antd": "^4.17.2",
"keycode": "^2.2.1",
"react": "^17.0.2",
Expand Down
4 changes: 4 additions & 0 deletions packages/dll/RROxDLL.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
<ClCompile Include="src\net\message.cpp" />
<ClCompile Include="src\net\messages\getdata.cpp" />
<ClCompile Include="src\net\messages\getinstances.cpp" />
<ClCompile Include="src\net\messages\getinstancesmulti.cpp" />
<ClCompile Include="src\net\messages\getstatic.cpp" />
<ClCompile Include="src\net\messages\getstruct.cpp" />
<ClCompile Include="src\net\messages\getstructlist.cpp" />
<ClCompile Include="src\net\messages\getstructtype.cpp" />
<ClCompile Include="src\net\messages\log.cpp" />
<ClCompile Include="src\net\messages\ready.cpp" />
<ClCompile Include="src\net\pipe.cpp" />
Expand All @@ -50,9 +52,11 @@
<ClInclude Include="src\net\message.h" />
<ClInclude Include="src\net\messages\getdata.h" />
<ClInclude Include="src\net\messages\getinstances.h" />
<ClInclude Include="src\net\messages\getinstancesmulti.h" />
<ClInclude Include="src\net\messages\getstatic.h" />
<ClInclude Include="src\net\messages\getstruct.h" />
<ClInclude Include="src\net\messages\getstructlist.h" />
<ClInclude Include="src\net\messages\getstructtype.h" />
<ClInclude Include="src\net\messages\log.h" />
<ClInclude Include="src\net\messages\ready.h" />
<ClInclude Include="src\net\pipe.h" />
Expand Down
12 changes: 12 additions & 0 deletions packages/dll/RROxDLL.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
<ClCompile Include="src\injector.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\net\messages\getstructtype.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\net\messages\getinstancesmulti.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\net\messages\getdata.h">
Expand Down Expand Up @@ -167,5 +173,11 @@
<ClInclude Include="src\injector.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\net\messages\getstructtype.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\net\messages\getinstancesmulti.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
23 changes: 23 additions & 0 deletions packages/dll/src/UE425/uobjectarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,29 @@ std::vector<FUObjectItem*> FUObjectArray::FindInstances(const UObject* obj, cons
return instances;
};

std::vector<std::tuple<UObject*, FUObjectItem*>> FUObjectArray::FindInstances(const std::vector<UObject*>& objs, const uint32_t count, const bool deep) {
std::vector<std::tuple<UObject*, FUObjectItem*>> instances;

for (int32_t i = 0; i < ObjObjects.NumElements; i++) {
FUObjectItem* item = ObjObjects.GetObjectPtr(i);

if (item && item->Object) {
for (auto obj : objs) {
if (item->Object->ClassPrivate == obj || (deep && HasSuper(obj, item->Object->ClassPrivate))) {
if (IsObjectTemplate(item->Object))
continue;

instances.push_back({ obj, item });
if (count > 0 && instances.size() == count)
return instances;
}
}
}
}

return instances;
};

FUObjectItem* FUObjectArray::FindStatic(const UObject* obj) {
for (int32_t i = 0; i < ObjObjects.NumElements; i++) {
FUObjectItem* item = ObjObjects.GetObjectPtr(i);
Expand Down
1 change: 1 addition & 0 deletions packages/dll/src/UE425/uobjectarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ struct FUObjectArray
FUObjectItem* FindInstance(const UObject* type);
FUObjectItem* FindStatic(const UObject* type);
std::vector<FUObjectItem*> FindInstances(const UObject* type, const uint32_t count = 0, const bool deep = false);
std::vector<std::tuple<UObject*, FUObjectItem*>> FindInstances(const std::vector<UObject*>& types, const uint32_t count = 0, const bool deep = false);
};
14 changes: 14 additions & 0 deletions packages/dll/src/injector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "./net/messages/getstatic.h"
#include "./net/messages/getstruct.h"
#include "./net/messages/getstructlist.h"
#include "./net/messages/getstructtype.h"
#include "./net/messages/getinstancesmulti.h"
#include "./net/messages/ready.h"

size_t FNameEntryAllocator::NumEntries = 0;
Expand Down Expand Up @@ -148,6 +150,18 @@ void Injector::processMessages() {
req.Process();
break;
}
case MessageType::GET_STRUCT_TYPE: {
GetStructTypeRequest req = GetStructTypeRequest(message);
req.pipe = &communicator;
req.Process();
break;
}
case MessageType::GET_INSTANCES_MULTI: {
GetInstancesMultiRequest req = GetInstancesMultiRequest(message);
req.pipe = &communicator;
req.Process();
break;
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/dll/src/net/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ enum class MessageType : uint16_t {
GET_DATA = 5,
GET_INSTANCES = 6,
GET_STATIC = 7,
GET_STRUCT_TYPE = 8,
GET_INSTANCES_MULTI = 9
};

class Message {
Expand Down
57 changes: 57 additions & 0 deletions packages/dll/src/net/messages/getinstancesmulti.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "getinstancesmulti.h"
#include "../message.h"
#include "../../injector.h"
#include "../../UE425/uobjectarray.h"
#include "../../UE425/uobject.h"

GetInstancesMultiRequest::GetInstancesMultiRequest(Buffer& data) : Request(data), names() {
uint64_t namesSize = data.Read<uint64_t>();
for (uint64_t i =0; i < namesSize; i++)
{
names.push_back(data.Read());
}

count = data.Read<uint32_t>();
deep = data.Read<bool>();
}

void GetInstancesMultiRequest::Process() {
GetInstancesMultiResponse res;

std::unordered_map<UObject*, uint32_t> indices;
std::vector<UObject*> objects;
uint32_t index = 0;
for (auto name : names) {
FUObjectItem* item = injector.memory.getSymbol<FUObjectArray>()->FindObject(name);
if (item && item->Object) {
objects.push_back(item->Object);
indices.insert({ item->Object, index });
}
index++;
}

std::vector<std::tuple<UObject*, FUObjectItem*>> found = injector.memory.getSymbol<FUObjectArray>()->FindInstances(objects, count, deep);
for (auto tuple : found) {
UObject* type = std::get<0>(tuple);
FUObjectItem* item = std::get<1>(tuple);
std::unordered_map<UObject*, uint32_t>::const_iterator index = indices.find(type);

if (!item || !item->Object || index == indices.end())
continue;

res.data.push_back({ index->second, item->Object->GetFullName() });
}

ProcessResponse(res);
}

void GetInstancesMultiResponse::Process(Buffer& buffer) {
Response::Process(buffer);

buffer.Write(data.size());
for (auto& item : data)
{
buffer.Write(std::get<0>(item));
buffer.Write(std::get<1>(item));
}
}
26 changes: 26 additions & 0 deletions packages/dll/src/net/messages/getinstancesmulti.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#pragma once
#include <string>
#include "../message.h"
#include "../../generator.h"

class GetInstancesMultiRequest : public Request {
public:
std::vector<std::string> names;
uint32_t count;
bool deep;

GetInstancesMultiRequest(Buffer& data);

void Process() override;
};

class GetInstancesMultiResponse : public Response {
public:
std::vector<std::tuple<uint32_t, std::string>> data;

GetInstancesMultiResponse() : Response(MessageType::GET_INSTANCES_MULTI) {};
GetInstancesMultiResponse(std::vector<std::tuple<uint32_t, std::string>> data) : data(data), Response(MessageType::GET_INSTANCES_MULTI) {};

void Process(Buffer& data) override;
};
8 changes: 4 additions & 4 deletions packages/dll/src/net/messages/getstruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ void GetStructRequest::Process() {
void GetStructResponse::Process(Buffer& data) {
Response::Process(data);

data.Write(type);
data.Write(structType);

if (type == StructResponseType::Struct && structObj)
if (structType == StructResponseType::Struct && structObj)
structObj->Serialize(data);
else if (type == StructResponseType::Function && functionObj)
else if (structType == StructResponseType::Function && functionObj)
functionObj->Serialize(data);
else if (type == StructResponseType::Enum && enumObj)
else if (structType == StructResponseType::Enum && enumObj)
enumObj->Serialize(data);
}
10 changes: 5 additions & 5 deletions packages/dll/src/net/messages/getstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class GetStructResponse : public Response {
std::unique_ptr<GeneratedStruct> structObj{};
std::unique_ptr<GeneratedEnum> enumObj{};
std::unique_ptr<GeneratedFunction> functionObj{};
StructResponseType type;
StructResponseType structType;

public:
GetStructResponse() : type(StructResponseType::NotFound), Response(MessageType::GET_STRUCT) {};
GetStructResponse(GeneratedStruct* structObj) : type(StructResponseType::Struct), structObj(structObj), Response(MessageType::GET_STRUCT) {};
GetStructResponse(GeneratedEnum* enumObj) : type(StructResponseType::Enum), enumObj(enumObj), Response(MessageType::GET_STRUCT) {};
GetStructResponse(GeneratedFunction* functionObj) : type(StructResponseType::Function), functionObj(functionObj), Response(MessageType::GET_STRUCT) {};
GetStructResponse() : structType(StructResponseType::NotFound), Response(MessageType::GET_STRUCT) {};
GetStructResponse(GeneratedStruct* structObj) : structType(StructResponseType::Struct), structObj(structObj), Response(MessageType::GET_STRUCT) {};
GetStructResponse(GeneratedEnum* enumObj) : structType(StructResponseType::Enum), enumObj(enumObj), Response(MessageType::GET_STRUCT) {};
GetStructResponse(GeneratedFunction* functionObj) : structType(StructResponseType::Function), functionObj(functionObj), Response(MessageType::GET_STRUCT) {};

void Process(Buffer& data) override;
};

0 comments on commit 65117bb

Please sign in to comment.