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

Can't get static classes #52

Closed
desumachii opened this issue Sep 25, 2023 · 15 comments
Closed

Can't get static classes #52

desumachii opened this issue Sep 25, 2023 · 15 comments

Comments

@desumachii
Copy link

desumachii commented Sep 25, 2023

i was trying to get the static class in my internal but it gives me no result

/*Objects & Names inits*/

auto GStatic = (SDK::UGameplayStatics*)SDK::UGameplayStatics::StaticClass();/// 0000000000

but when i try to get those static classes on the dumper it gives me results

UEClass GStatic = ObjectArray::FindClassFast("GameplayStatics"); /// 000000002D064E40
@Fischsalat
Copy link
Collaborator

Strange. Can you send me the sdk?

@desumachii
Copy link
Author

@Fischsalat
Copy link
Collaborator

bruh, you didn't even send the sdk.

@desumachii
Copy link
Author

sorry for that, there's the new one https://www.mediafire.com/file/2ncu6r97yzl8sy6/SDK.zip/file

@Fischsalat
Copy link
Collaborator

Instead of the first example from above you're supposed to use ::GetDefault() instad. Also, does finding other objects work? Can you iterate over GObjects, does UObject::GObjects->GetByIndex(30) return a valid pointer?

@desumachii
Copy link
Author

desumachii commented Sep 26, 2023

Instead of the first example from above you're supposed to use ::GetDefault() instad. Also, does finding other objects work? Can you iterate over GObjects, does UObject::GObjects->GetByIndex(30) return a valid pointer?

no it doesn't return a valid pointer

@desumachii
Copy link
Author

image
in my log the pointer was 0x2cb45dc0 but on the dump it was 0x2cb35dc0

@Fischsalat
Copy link
Collaborator

Heap memory is dynamic, addresses change when restarting. So does everything work? you also need to show me what you're printing, not just the result.

@desumachii
Copy link
Author

desumachii commented Sep 26, 2023

Heap memory is dynamic, addresses change when restarting. So does everything work? you also need to show me what you're printing, not just the result.

getting static class works now.

for some reason when im using the "GetAllActorsOfClass"
it crash at Class->GetFunction("GameplayStatics", "GetAllActorsOfClass");

image

//init
GPStatics = (SDK::UGameplayStatics*)SDK::UGameplayStatics::StaticClass()->GetDefaultObj(); //get StaticClass defaultObj

//caching
SDK::TArraySDK::AActor* actors;
GPStatics->GetAllActorsOfClass(World, (SDK::AActor*)SDK::AArkPlayer::StaticClass(), &actors);

@Fischsalat
Copy link
Collaborator

what kind of pseudocode is that? send the actual code you're using

@desumachii
Copy link
Author

what kind of pseudocode is that? send the actual code you're using

it just a bunch of printf. i can't actually debug cuz the AC is active

void UGameplayStatics::GetAllActorsOfClass(class UObject* WorldContextObject, class AActor* ActorClass, TArray<class AActor*>* OutActors)
{
	printf("GetAllActorsOfClass Starting\n");
	static class UFunction* Func = nullptr;

	if (!Func)
		Func = Class->GetFunction("GameplayStatics", "GetAllActorsOfClass");

	Params::UGameplayStatics_GetAllActorsOfClass_Params Parms{};

	Parms.WorldContextObject = WorldContextObject;
	Parms.ActorClass = ActorClass;

	auto Flgs = Func->FunctionFlags;
	Func->FunctionFlags |= 0x400;
	printf("GetAllActorsOfClass ProcessEvent start\n");
	UObject::ProcessEvent(Func, &Parms);
	printf("GetAllActorsOfClass ProcessEvent end\n");


	Func->FunctionFlags = Flgs;

	if (OutActors != nullptr)
		*OutActors = std::move(Parms.OutActors);
	printf("GetAllActorofClass Ending\n");
}
class UFunction* UClass::GetFunction(const std::string& ClassName, const std::string& FuncName)
	{
		printf("GetFunction [%s][%s]\n", ClassName.c_str(), FuncName.c_str());
		for(UStruct* Clss = this; Clss; Clss = Clss->Super)
		{
			printf("for(UStruct* Clss = this; Clss; Clss = Clss->Super) [%llx] [%s]\n", (void*)Clss, Clss->GetName().c_str());
			if (Clss->GetName() == ClassName)
			{
				printf("if (Clss->GetName() == ClassName) [%s]\n", Clss->GetName().c_str());
				for (UField* Field = Clss->Children; Field; Field = Field->Next)
				{
					printf("for (UField* Field = Clss->Children; Field; Field = Field->Next) [%llx]\n", (void*)Field);
					if(Field->HasTypeFlag(EClassCastFlags::Function) && Field->GetName() == FuncName)
					{
						printf("if(Field->HasTypeFlag(EClassCastFlags::Function) && Field->GetName() == FuncName) [%s]\n", Field->GetName().c_str());
						return static_cast<class UFunction*>(Field);
					}	
				}
			}
		}
		return nullptr;
	}
	```

@desumachii
Copy link
Author

desumachii commented Sep 26, 2023

if (ue->SetObjects())
	{
		auto MyController = ue->PlayerController;
		auto MyPawn = ue->World->OwningGameInstance->LocalPlayers[0]->PlayerController->Pawn;
		auto MyPlayer = ue->PlayerController->K2_GetPawn();
		auto CamManager = ue->PlayerController->PlayerCameraManager;
		auto MyLoc = ue->PlayerController->PlayerCameraManager->GetCameraLocation();
		auto MyRot = ue->PlayerController->PlayerCameraManager->GetCameraRotation();


		SDK::TArray<SDK::AActor*> actors;
		ue->GPStatics->GetAllActorsOfClass(ue->World, (SDK::AActor*)SDK::AArkPlayer::StaticClass(), &actors);
		
		for (int i = 0; i < actors.Num(); i++)
		{
			auto actor = actors[i];
			ImGui::Text("Actor [%s]", actor->GetName().c_str());
		}
		}
	static bool SetObjects()
	{
		//set MathLib for math functions
		if (!MathLib) MathLib = (SDK::UKismetMathLibrary*)SDK::UKismetMathLibrary::StaticClass();

		//set SystemLib for math functions
		if (!KismetSystemLib) KismetSystemLib = (SDK::UKismetSystemLibrary*)SDK::UKismetSystemLibrary::StaticClass();

		//Set GPStatics for game functions
		if (!GPStatics) GPStatics = (SDK::UGameplayStatics*)SDK::UGameplayStatics::StaticClass()->GetDefaultObj();
		if (!GPStatics) return false;

		World = *GWorld;
		//check world
		if (!World) return false;

		//Set local player 
		if (World->OwningGameInstance && World->OwningGameInstance->LocalPlayers.IsValidIndex(0)) LocalPlayer = World->OwningGameInstance->LocalPlayers[0];
		if (!LocalPlayer) return false;

		//Set player contoller
		if (LocalPlayer) PlayerController = LocalPlayer->PlayerController;
		if (!PlayerController) return false;

		//Everything went well
		return true;
	}

@Fischsalat
Copy link
Collaborator

SDK::UGameplayStatics::StaticClass()->GetDefaultObj() -> SDK::UGameplayStatics::GetDefaultObj();

you're somehow mananging to call "GetAllActorsOfClass" on an instance of a UClass, call it on an actual GameplayStatics object

@desumachii
Copy link
Author

image
it works!! thanks alot

@Fischsalat
Copy link
Collaborator

:|

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants