Загружать данные из .ini, сбить мою игру! Что я могу сделать? C ++ - PullRequest
0 голосов
/ 17 мая 2018

Здравствуйте. Я пытаюсь создать скрипт для сохранения / загрузки моего пользовательского макета оружия для моей игры. Функция сохранения работает нормально, но если я хочу загрузить макет, это приводит к сбою в моей игре. Я знаю, в чем проблема, но не знаю, как их исправить, поэтому мне нужны ваши знания!

void SaveWeaponsLayout()
{
    Ini wpLayout = (".\\Files\\Settings\\WeaponsLayout.ini");
    Log::Msg("Reading Data for WeaponsLayout.ini!");
    Player playerPed = PLAYER::PLAYER_PED_ID();
    if (!ENTITY::IS_ENTITY_DEAD(playerPed))
    {
        for (auto & wpID : weaponLayoutList)
        {
            Hash weapon = wpID.weaponHash;
            char * wpName = wpID.WeaponName;
            if (WEAPON::HAS_PED_GOT_WEAPON(playerPed, wpID.weaponHash, 0))
            {
                int weaponInHex = weapon;
                std::string weaponInHex_ = hexify< int >(weaponInHex);
                wpLayout.WriteString(weaponInHex_, wpName, "WEAPONHASH");
            }
            for (auto & wpCompID : weaponComponentList)
            {
                Hash weaponComp = wpCompID.weaponCompHash;
                char * wpCompName = wpCompID.weaponComponent;
                if (WEAPON::HAS_PED_GOT_WEAPON_COMPONENT(playerPed, wpID.weaponHash, wpCompID.weaponCompHash))
                {
                    int weaponCompInHex = weaponComp;
                    std::string weaponCompInHex_ = hexify< int >(weaponCompInHex);
                    wpLayout.WriteString(weaponCompInHex_, wpName, wpCompName);
                }
            }
        }
    }
    Log::Msg("Files WeaponsLayout.ini created!");
    Notifications::MessageCentre6000("~p~Saved~s~: Weapons Layout");
}

Список, где я получаю данные об оружии из игры >>

static struct wpList
{
    __int64 weaponHash;
    char * WeaponName;
};
static std::vector<wpList> weaponLayoutList{
    //{ 0xA2719263, "Unarmed" },
{ 0xFBAB5776, "Parachute" },
{ 0x99B507EA, "Knife" },
{ 0x8BB05FD7, "Flashlight" },
{ 0xCD274149, "Battle Axe" },
{ 0x94117305, "Pool Cue" },
...
}; // 88x Weapons

Список, где я получаю данные об оружейных компонентах из игры >>

static struct wpCompList
{
    unsigned int weaponCompHash;
    char * weaponComponent;
};

static std::vector<wpCompList> weaponComponentList{
    { 0x75414F30, "COMPONENT_AT_RAILCOVER_01" },
{ 0x0C164F53, "COMPONENT_AT_AR_AFGRIP" },
{ 0x359B7AAE, "COMPONENT_AT_PI_FLSH" },
{ 0x7BC4CDDC, "COMPONENT_AT_AR_FLSH" },
{ 0x9D2FBF29, "COMPONENT_AT_SCOPE_MACRO" },
...
}; // 551x Weapon Components

Это файл WeaponsLayout.ini, который я сохранил!

[Micro SMG]
WEAPONHASH=0x13532244
COMPONENT_AT_PI_FLSH=0x359b7aae
COMPONENT_AT_AR_SUPP_02=0xa73d4664
COMPONENT_MICROSMG_CLIP_02=0x10e6ba2b
[Assault Rifle]
WEAPONHASH=0xbfefff6d
COMPONENT_ASSAULTRIFLE_CLIP_03=0xdbf0a53d
[Advanced Rifle]
WEAPONHASH=0xaf113f99
COMPONENT_AT_AR_FLSH=0x7bc4cddc
COMPONENT_ADVANCEDRIFLE_CLIP_01=0xfa8fa10f
[Pump Shotgun]
WEAPONHASH=0x1d073a89
COMPONENT_AT_AR_FLSH=0x7bc4cddc
COMPONENT_AT_SR_SUPP=0xe608b35e
COMPONENT_PUMPSHOTGUN_CLIP_01=0xd16f1438
COMPONENT_PUMPSHOTGUN_VARMOD_LOWRIDER=0xa2d79ddb

... так что теперь мой скрипт вызывает у меня проблемы, потому что он ищет в моем файле все оружие и компоненты оружия!

void LoadWeaponsLayout()
{
    Log::Msg("Files reading WeaponsLayout.ini!");
    Ini wpLayout = (".\\Files\\Settings\\WeaponsLayout.ini");
    Player playerPed = PLAYER::PLAYER_PED_ID();
    if (!ENTITY::IS_ENTITY_DEAD(playerPed))
    {
        for (auto wpID : weaponLayoutList)
        {
            char * wpName = wpID.WeaponName;
            unsigned weaponX = wpLayout.GetInt(wpName, "WEAPONHASH");
            if (!WEAPON::HAS_PED_GOT_WEAPON(playerPed, weaponX, 0))
            {
                WEAPON::GIVE_DELAYED_WEAPON_TO_PED(playerPed, weaponX, 9999, 0);
                for (auto wpCompID : weaponComponentList)
                {
                    char * wpCompoName = wpCompID.weaponComponent;
                    unsigned weaponComp = wpLayout.GetInt(wpName, wpCompoName);
                    WAIT(0);
                    if (WEAPON::DOES_WEAPON_TAKE_WEAPON_COMPONENT(weaponX, weaponComp))
                    {
                        WEAPON::GIVE_WEAPON_COMPONENT_TO_PED(playerPed, weaponX, weaponComp);
                    }
                }
            }
        }
    }
    Log::Msg("Files WeaponsLayout.ini loaded!");
    Notifications::MessageCentre4000("~p~Loaded~s~: Weapons Layout");
}   

[мой начальный класс]

class Ini
{
private:
    std::string inifile;
public:

    Ini(std::string file)
    {
        this->inifile = file;
    }

    void WriteString(std::string string, std::string app, std::string key)
    {
        WritePrivateProfileStringA(app.c_str(), key.c_str(), string.c_str(), this->inifile.c_str());
    }

    std::string GetString(std::string app, std::string key)
    {
        char buf[100];
        GetPrivateProfileStringA(app.c_str(), key.c_str(), "NULL", buf, 100, this->inifile.c_str());
        return (std::string)buf;
    }

    void WriteInt(int value, std::string app, std::string key)
    {
        WriteString(std::to_string(value), app, key);
    }

    int GetInt(std::string app, std::string key)
    {
        return std::stoi(GetString(app, key));
    }
}

DEBUG:

Files reading WeaponsLayout.ini!
Exception thrown at 0x000007FEFD71A06D in GTA5.exe: Microsoft C++ exception: std::invalid_argument at memory location 0x000000013AD4E610.
The thread 0x4628 has exited with code 0 (0x0).
The thread 0x4d78 has exited with code 0 (0x0).
The thread 0x4cd0 has exited with code 0 (0x0).
The thread 0x3c20 has exited with code 0 (0x0).
The thread 0x3678 has exited with code 0 (0x0).
The thread 0x1278 has exited with code 0 (0x0).
The thread 0x59a0 has exited with code 0 (0x0).
The thread 0x5458 has exited with code 0 (0x0).
The thread 0x4a8c has exited with code 0 (0x0).
The thread 0x5300 has exited with code 0 (0x0).
The thread 0x4b20 has exited with code 0 (0x0).
The thread 0x526c has exited with code 0 (0x0).
The thread 0x500c has exited with code 0 (0x0).
The thread 0x4be0 has exited with code 0 (0x0).
The thread 0x266c has exited with code 0 (0x0).
The thread 0x59ec has exited with code 0 (0x0).
The thread 0x3020 has exited with code 0 (0x0).
The thread 0x581c has exited with code 0 (0x0).
The thread 0x5098 has exited with code 0 (0x0).
The thread 0xd98 has exited with code 0 (0x0).
The thread 0x5180 has exited with code 0 (0x0).
The thread 0x1cc8 has exited with code 0 (0x0).
The thread 0x4c84 has exited with code 0 (0x0).
The thread 0x112c has exited with code 0 (0x0).
The thread 0x2dc0 has exited with code 0 (0x0).
The thread 0x5910 has exited with code 0 (0x0).
The thread 0x59cc has exited with code 0 (0x0).
The thread 0x2eb4 has exited with code 0 (0x0).
The thread 0x5aec has exited with code 0 (0x0).
The thread 0x58cc has exited with code 0 (0x0).
The thread 0x5a94 has exited with code 0 (0x0).
The thread 0x481c has exited with code 0 (0x0).
The thread 0x5554 has exited with code 0 (0x0).
The thread 0x2358 has exited with code 0 (0x0).
The thread 0x1b70 has exited with code 0 (0x0).
The thread 0x5764 has exited with code 0 (0x0).
The thread 0x53cc has exited with code 0 (0x0).
The thread 0x4ba4 has exited with code 0 (0x0).
The thread 0x4008 has exited with code 0 (0x0).
The thread 0x566c has exited with code 0 (0x0).
The thread 0x415c has exited with code 0 (0x0).
The thread 0x4cc0 has exited with code 0 (0x0).
The thread 0x512c has exited with code 0 (0x0).
The thread 0x5614 has exited with code 0 (0x0).
The thread 0x5390 has exited with code 0 (0x0).
The thread 0x4d68 has exited with code 0 (0x0).
The thread 0x56e8 has exited with code 0 (0x0).
The thread 0x54e8 has exited with code 0 (0x0).
The thread 0x1bc0 has exited with code 0 (0x0).
The thread 0x55d0 has exited with code 0 (0x0).
The thread 0x4f1c has exited with code 0 (0x0).
The thread 0x4efc has exited with code 0 (0x0).
The thread 0x54b4 has exited with code 0 (0x0).
The thread 0x4144 has exited with code 0 (0x0).
The thread 0x614 has exited with code 0 (0x0).
The thread 0x5820 has exited with code 0 (0x0).
The thread 0x4878 has exited with code 0 (0x0).
The thread 0x4184 has exited with code 0 (0x0).
The thread 0x2064 has exited with code 0 (0x0).
The thread 0x568c has exited with code 0 (0x0).
The thread 0x30cc has exited with code 0 (0x0).
The thread 0x57d8 has exited with code 0 (0x0).
The thread 0x5658 has exited with code 0 (0x0).
The thread 0x4c94 has exited with code 0 (0x0).
The thread 0x5084 has exited with code 0 (0x0).
The thread 0x4ff4 has exited with code 0 (0x0).
The thread 0x5858 has exited with code 0 (0x0).
The thread 0x148c has exited with code 0 (0x0).
The thread 0x209c has exited with code 0 (0x0).
The thread 0x52bc has exited with code 0 (0x0).
The thread 0x5170 has exited with code 0 (0x0).
The thread 0x1388 has exited with code 0 (0x0).
The thread 0xc10 has exited with code 0 (0x0).
The thread 0x12c0 has exited with code 0 (0x0).
The thread 0xca8 has exited with code 0 (0x0).
The thread 0x2040 has exited with code 0 (0x0).
The thread 0x4d1c has exited with code 0 (0x0).
The thread 0x358c has exited with code 0 (0x0).
The thread 0x1eac has exited with code 0 (0x0).
The thread 0x5608 has exited with code 0 (0x0).
The thread 0x28d8 has exited with code 0 (0x0).
The thread 0x4c44 has exited with code 0 (0x0).
The thread 0x5a0c has exited with code 0 (0x0).
The thread 0x4420 has exited with code 0 (0x0).
The thread 0x5828 has exited with code 0 (0x0).
The thread 0x29f4 has exited with code 0 (0x0).
The thread 0x4e60 has exited with code 0 (0x0).
The thread 0x54c4 has exited with code 0 (0x0).
The thread 0x4564 has exited with code 0 (0x0).
The thread 0x50ec has exited with code 0 (0x0).
The thread 0x43cc has exited with code 0 (0x0).
The thread 0x4e74 has exited with code 0 (0x0).
The thread 0x549c has exited with code 0 (0x0).
The thread 0xd74 has exited with code 0 (0x0).
The thread 0x5b90 has exited with code 0 (0x0).
The thread 0x4f7c has exited with code 0 (0x0).
The thread 0x30e8 has exited with code 0 (0x0).
The thread 0x4f74 has exited with code 0 (0x0).
The thread 0x1530 has exited with code 0 (0x0).
The thread 0x5584 has exited with code 0 (0x0).
DXGI WARNING: Process is terminating. Using simple reporting. Please call ReportLiveObjects() at runtime for standard reporting. [ STATE_CREATION WARNING #0: ]
DXGI WARNING: Live Producer at 0x0000000000474EA8, Refcount: 4. [ STATE_CREATION WARNING #0: ]
DXGI WARNING:   Live Object at 0x0000000000488880, Refcount: 4. [ STATE_CREATION WARNING #0: ]
DXGI WARNING:   Live Object at 0x00000000004640E0, Refcount: 1. [ STATE_CREATION WARNING #0: ]
DXGI WARNING: Live                         Object :      2 [ STATE_CREATION WARNING #0: ]
The program '[22656] GTA5.exe' has exited with code 0 (0x0).
...