VeroFess / PalWorld-Server-Unoffical-Api

A PalWorld Server API like minecraft bukkit, not finish yet
275 stars 17 forks source link

Injecting too early #20

Closed piz-ewing closed 9 months ago

piz-ewing commented 9 months ago

Injecting too early, requires a flag to determine whether the object has been created

piz-ewing commented 9 months ago

Temporary solution

sdk-basic.cpp

#include "SDKDirect.h"
#include <chrono>
#include <thread>

SDK::UWorld              *SDK::World       = nullptr;
SDK::APalGameStateInGame *SDK::StateInGame = nullptr;

bool SDK::sdk_init() {

    for (size_t times=0; times<10; times++) {
        if (World == nullptr) {
            World = *reinterpret_cast<SDK::UWorld **>(uintptr_t(GetImageBaseOffset()) + Offsets::GWorld);
        }

        if (World != nullptr) {
            StateInGame = GetPalGameStateInGame(World);
            if (StateInGame != nullptr) {
                return true;
            }
        }

        std::this_thread::sleep_for(std::chrono::seconds(1));
    }

    return false;
}