Информация Полезные функции

_=Gigant=_

Известный
144
221
Functions to add names to the file, could be useful for friends list etc... not just names other text in general:
void WriteNamesToFile(const std::string& filename, const std::set<std::string>& names) {
    std::ofstream outfile(filename);
    for (const auto& name : names) {
        if (!name.empty()) {
            outfile << name << std::endl;
        }
    }
}

void AddNameToFile(const std::string& filename, const std::string& new_name) {
    std::set<std::string> names = ReadNamesFromFile(filename);
    if (new_name.empty() || names.find(new_name) != names.end())
        return;
   
    names.insert(new_name);
    WriteNamesToFile(filename, names);
}
//name_to_remove or in general any text
void RemoveNameFromFile(const std::string& filename, const std::string& name_to_remove) {
    std::set<std::string> names = ReadNamesFromFile(filename);
    if (names.erase(name_to_remove) > 0)
        WriteNamesToFile(filename, names);
   
}

bool NameExistsInFile(const std::string& filename, const std::string& name_to_check) {
    std::set<std::string> names = ReadNamesFromFile(filename);
    return names.find(name_to_check) != names.end();
}

std::set<std::string> ReadNamesFromFile(const std::string& filename) {
    std::set<std::string> names;
    std::ifstream infile(filename);
    std::string name;
    while (std::getline(infile, name)) {
        if (!name.empty())
            names.insert(name);       
    }
    return names;
}
 

walkerdev

Новичок
7
0
SAMPFuncs - управление выносливостью игрока


Функции get/set:
float getFloatFromMemory(unsigned char* memoryAddress) {
    float* floatPtr = reinterpret_cast<float*>(memoryAddress);
    return *floatPtr;
}
void setFloatToMemory(unsigned char* memoryAddress, float value) {
    float* floatPtr = reinterpret_cast<float*>(memoryAddress);
    *floatPtr = value * 31.47000244;
}


Пример использования:
    unsigned char* memoryAddress = reinterpret_cast<unsigned char*>(0xB7CDB4);

    float value = 0.0f;

    if (type >= 20) value = 100.0f;
    else if (type >= 10 && type <= 19) value = 0.0f;
    else if (type >= 4 && type <= 9) value = -10.0f;
    else value = -100.0f;

    setFloatToMemory(memoryAddress, value);
    float floatValue = getFloatFromMemory(memoryAddress);
type - в моем случае переменная, которая передается из pawn-кода, отвечающая за выносливость игрока.
 
  • Bug
Реакции: Smeruxa