Другое С/С++ Вопрос - Ответ

MrEnderStail

Новичок
19
0
нужна помощь с кодом ( ниже ).
Задание :11 знаков после десятичной точки. Но я не пойму как получить 11 знаков после точки.

И если кто то знает скиньте руководство по типом данных( float double и тд. И как их использовать , комбинировать и тд)
дада:
#include <stdio.h>
#include <math.h>
#include <locale.h>

int m;
int Z;
int X;
int B;
int C;
float V;
; int main(void)
{
    setlocale(LC_CTYPE, "rus");
        printf("Введите m: ");
        scanf_s("%d", &m);
            B = pow(3 * m, 2);
            X = sqrt((B+4) - (24 * m));
            C = 3 * sqrt(m) - 2 / sqrt(m);
            V = X / C;
        printf("%d\n" ,X);
        printf("%d\n", C);
        printf("%f\n", V);
    return 0;
}
 

AdCKuY_DpO4uLa

Известный
287
477
нужна помощь с кодом ( ниже ).
Задание :11 знаков после десятичной точки. Но я не пойму как получить 11 знаков после точки.

И если кто то знает скиньте руководство по типом данных( float double и тд. И как их использовать , комбинировать и тд)
дада:
#include <stdio.h>
#include <math.h>
#include <locale.h>

int m;
int Z;
int X;
int B;
int C;
float V;
; int main(void)
{
    setlocale(LC_CTYPE, "rus");
        printf("Введите m: ");
        scanf_s("%d", &m);
            B = pow(3 * m, 2);
            X = sqrt((B+4) - (24 * m));
            C = 3 * sqrt(m) - 2 / sqrt(m);
            V = X / C;
        printf("%d\n" ,X);
        printf("%d\n", C);
        printf("%f\n", V);
    return 0;
}
C:
#include <stdio.h>
#include <math.h>

int main()
{
    double m, Z, X, B, C, V;
    
    printf("Введите m: ");
    scanf("%lf", &m);
    
    B = pow(3 * m, 2);
    X = sqrt((B + 4) - (24 * m));
    C = 3 * sqrt(m) - 2 / sqrt(m);
    V = X / C;
    
    printf("%0.11lf\n%0.11lf\n%0.11lf", X, C, V);
    
    return 0;
}
 

Dark_Knight

Me, me and me.
Друг
4,062
2,077
Ты про это?
1633206472552.png
 

DANIIL XPC

Известный
81
5
How can i remake this in c++ sf?
C++:
    sampRegisterChatCommand('kr', k1d)



function k1d(params)
    if params ~= nil then
        lua_thread.create(function()
                sampSendChat("text")
                wait(2000)
                sampSendChat("text2")
    end)
    end
end
 

legendabrn

Известный
Проверенный
122
172
How can i remake this in c++ sf?
C++:
    sampRegisterChatCommand('kr', k1d)



function k1d(params)
    if params ~= nil then
        lua_thread.create(function()
                sampSendChat("text")
                wait(2000)
                sampSendChat("text2")
    end)
    end
end
C++:
#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS

#include <assert.h>
#include <thread>

#include "SAMPFUNCS_API.h"
#include "game_api\game_api.h"

SAMPFUNCS *SF = new SAMPFUNCS();

void CALLBACK k1d(std::string params)
{
    std::thread test([]()
    {
        SF->getSAMP()->getChat()->AddChatMessage(D3DCOLOR_XRGB(0, 0xAA, 0), "text");
        std::this_thread::sleep_for(std::chrono::milliseconds(2000));
        SF->getSAMP()->getChat()->AddChatMessage(D3DCOLOR_XRGB(0, 0xAA, 0), "text2");
    });
    test.detach();
}

void CALLBACK mainloop()
{
    static bool init = false;
    if (!init)
    {
        if (GAME == nullptr && GAME->GetSystemState() != eSystemState::GS_PLAYING_GAME && !SF->getSAMP()->IsInitialized()) return;
        SF->getSAMP()->registerChatCommand("kr", k1d);
        init = true;
    }
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID lpReserved)
{
    if(dwReasonForCall == DLL_PROCESS_ATTACH) SF->initPlugin(mainloop, hModule);
    return TRUE;
}
 
  • Злость
Реакции: Dark_Knight

kin4stat

mq-team
Всефорумный модератор
2,730
4,710
C++:
#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS

#include <assert.h>
#include <thread>

#include "SAMPFUNCS_API.h"
#include "game_api\game_api.h"

SAMPFUNCS *SF = new SAMPFUNCS();

void CALLBACK k1d(std::string params)
{
    std::thread test([]()
    {
        SF->getSAMP()->getChat()->AddChatMessage(D3DCOLOR_XRGB(0, 0xAA, 0), "text");
        std::this_thread::sleep_for(std::chrono::milliseconds(2000));
        SF->getSAMP()->getChat()->AddChatMessage(D3DCOLOR_XRGB(0, 0xAA, 0), "text2");
    });
    test.detach();
}

void CALLBACK mainloop()
{
    static bool init = false;
    if (!init)
    {
        if (GAME == nullptr && GAME->GetSystemState() != eSystemState::GS_PLAYING_GAME && !SF->getSAMP()->IsInitialized()) return;
        SF->getSAMP()->registerChatCommand("kr", k1d);
        init = true;
    }
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID lpReserved)
{
    if(dwReasonForCall == DLL_PROCESS_ATTACH) SF->initPlugin(mainloop, hModule);
    return TRUE;
}
Ага, здарова UB
 

kin4stat

mq-team
Всефорумный модератор
2,730
4,710
самый красивый вариант
or
самый уебанский вариант
or
что-то между:

C++:
#include "SAMPFUNCS_API.h"
#include "game_api\game_api.h"

#include <functional>
#include <chrono>
#include <list>

class Timer {
    struct TimerInfo {
        std::chrono::steady_clock::time_point start;
        std::chrono::milliseconds duration;
        std::function<void()> callback;

        TimerInfo(std::chrono::steady_clock::time_point s, std::chrono::milliseconds dur, std::function<void()> cb) : start(s), duration(dur), callback(cb) {}
    };

public:
    static Timer& Instance() {
        static Timer inst;
        return inst;
    }

    void Update() {
        using namespace std::chrono;
        for (auto it = timers.begin(); it != timers.end();) {
            auto& timer = *it;
            if (steady_clock::now() - timer.start > timer.duration) {
                timer.callback();
                timers.erase(it++);
            }
            else {
                ++it;
            }
        }
    }

    void AddTimer(std::function<void()> callback, std::chrono::milliseconds duration) {
        timers.emplace_back(std::chrono::steady_clock::now(), duration, callback);
    }

    std::list<TimerInfo> timers;
};

SAMPFUNCS *SF = new SAMPFUNCS();

void CALLBACK k1d(std::string params)
{
    using namespace std::chrono_literals;
    SF->getSAMP()->getChat()->AddChatMessage(0xFF00FF00, "text");
    Timer::Instance().AddTimer([] {
        SF->getSAMP()->getChat()->AddChatMessage(0xFFFF0000, "text2");
    }, 3s);
}

void CALLBACK mainloop()
{
    Timer::Instance().Update();
    static bool init = false;
    if (!init)
    {
        if (GAME == nullptr &&
            GAME->GetSystemState() != eSystemState::GS_PLAYING_GAME &&
            !SF->getSAMP()->IsInitialized())
            return;
        SF->getSAMP()->registerChatCommand("kr", k1d);
        init = true;
    }
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID)
{
    if (dwReasonForCall == DLL_PROCESS_ATTACH) {
        SF->initPlugin(mainloop, hModule);
    }
    return TRUE;
}

P.S. код таймера был написан за 5 минут как proof of concept, кто хочет - оптимизируйте
 

kin4stat

mq-team
Всефорумный модератор
2,730
4,710
1. Посмотреть вложение 117271
Есть код, но увы он в некоторых числах работает не правильно, хелп плиз

#include <iostream>
using namespace std;
int main()
{
long long n;
int reverse=0, rem;
//cout<<"Enter a number: ";
cin>>n;
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}
cout<<reverse<<endl;
//system("PAUSE");
return 0;
}
C++:
#include <string>
#include <algorithm>
#include <iostream>

int main() {
    std::string in{};
    std::cin >> in;
    bool negative = false;
    if (in[0] == '-') {
        negative = true;
        in = in.substr(1);
    }
    std::reverse(in.begin(), in.end());
    std::string out = std::to_string(std::stoll(in));
    if (negative) {
        out = "-" + out;
    }
    std::cout << out;
}
 
  • Нравится
Реакции: .deserve

THERION

Известный
Проверенный
88
324
Пытаюсь изменить
1634901282237.png

на
1634901345881.png

Если делать это через Сheat Engine то все работает прекрасно.
Программа которую я написал должна делать то же самое но не работает.
C:
#include <windows.h>
#include <string.h>
#include <stdlib.h>

void* ptr = (void*)0x2A3F4D; // fix: 0x2A3F4D => 0x6A3F4D
char patch[] = "\xB0\x05\x90\x90\x90\x90";

void write_memory(void) {
    DWORD old_prot;
    size_t size = sizeof(patch) - 1;

    VirtualProtect(ptr, size, PAGE_READWRITE, &old_prot);
    memcpy(ptr, patch, size);
    VirtualProtect(ptr, size, old_prot, &old_prot);
}

int __stdcall DllMain(HMODULE module, DWORD reason, LPVOID reserved) {
    if (reason == DLL_PROCESS_ATTACH)
            write_memory();
    return 1;
}
 
Последнее редактирование:

legendabrn

Известный
Проверенный
122
172
Пытаюсь изменить
Посмотреть вложение 118744
на
Посмотреть вложение 118745
Если делать это через Сheat Engine то все работает прекрасно.
Программа которую я написал должна делать то же самое но не работает.
Если скомпилировать код ниже и закинуть в папку с игрой Asi-loader выдает:
Посмотреть вложение 118746

C:
#include <windows.h>
#include <string.h>
#include <stdlib.h>

void write_memory(void) {
    DWORD old_prot;

    void* ptr = (void*)0x2A3F4D;
    char patch[] = "\xB0\x05\x90\x90\x90\x90";
    size_t size = sizeof(patch) - 1;

    VirtualProtect(ptr, size, PAGE_READWRITE, &old_prot);
    memcpy(ptr, patch, size);
    VirtualProtect(ptr, size, old_prot, &old_prot);

    return;
}

int __stdcall DllMain(HMODULE module, DWORD reason, LPVOID reserved)
{
    switch (reason)
    {
        case DLL_PROCESS_ATTACH:
            write_memory();
            break;
    }

    return 1;
}

Также пробовал написать тоже самое на Lua, но функции из библиотеки memory не работают

Lua:
local wrt = require('memory').setint8
local ptr = 0x2A3F4D

local result = wrt(ptr + 0, 0xB0, true)
result = result or wrt(ptr + 1, 0x05, true)
for i = 2, 5 do
    result = result or wrt(ptr + i, 0x90, true)
end
print(result) -- FALSE
C++:
void write_memory()
{
    DWORD old_prot;

    void* ptr = reinterpret_cast<void*>(0x6A3F4D);
    char patch[] = "\xB0\x05\x90\x90\x90\x90";
    size_t size = sizeof(patch) - 1;

    VirtualProtect(ptr, size, PAGE_READWRITE, &old_prot);
    memcpy(ptr, patch, size);
    VirtualProtect(ptr, size, old_prot, &old_prot);
}


BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
    if (ul_reason_for_call == DLL_PROCESS_ATTACH)
    {
        write_memory();
    }
    return TRUE;
}

1634902404939.png


upd: не работало потому что, ты пытался перезаписать только адрес смещения а не статический адрес
 
Последнее редактирование:
  • Нравится
Реакции: THERION

AdCKuY_DpO4uLa

Известный
287
477
C++:
#include <Windows.h>
#include <vector>

void WriteBytes(const unsigned __int32 &addr, const std::vector<unsigned __int8> &bytes) {
    DWORD prot;
    VirtualProtect((void*)addr, bytes.size(), PAGE_EXECUTE_READWRITE, &prot);
    memcpy((void*)addr, bytes.data(), bytes.size());
    VirtualProtect((void*)addr, bytes.size(), prot, &prot);
}

class CPlugin {
public:
    CPlugin() {
        WriteBytes(0x6A3F4D, { 0xB0, 0x05, 0x90, 0x90, 0x90, 0x90 });//install patch
    }

    ~CPlugin() {
        WriteBytes(0x6A3F4D, { 0x8A, 0x86, 0x8A, 0x04, 0x00, 0x00 });//remove patch if plugin unloaded
    }
} Plugin;

так красивее🤨