Объявления

Друзья, если не получается зарегистрироваться, напишите на почту vdv_forever@bk.ru.
Я оторву свою задницу от всех дел и обязательно Вас активирую! :smile10:
Добро пожаловать на геройский форум! :smile25:

Как создать плагин для HD мода

Герои Меча и Магии III: Возрождение Эрафии, Герои Меча и Магии III Дыхание Смерти, Герои Меча и Магии III Клинок Армагеддона, Герои Меча и Магии III Хроники Героев
offlineАватара пользователя
AlexSpl  
имя: Александр
Эксперт
Эксперт
 
Сообщения: 5547
Зарегистрирован: 17 сен 2010, 12:58
Пол: Мужчина
Награды: 14
Высшая медаль (1) Победителю турнира по HMM1_TE (2) Победителю этапа по HMM1 (1) Победителю этапа по HMM2 (1) Лучшему из лучших (1) 2 место 1 этапа по HMM1 (1)
3 место 1 этапа по HMM1 (1) 1 место 2 этапа по HMM2 (1) Победителю турнира по KB (2) Победителю турнира по KB (1) Грандмастер оффлайн-турниров (1) Боевой шлем (1)
Поблагодарили: 2162 раз.

Re: Как создать плагин для HD мода

Сообщение AlexSpl » 03 апр 2019, 14:39

Цитата:
The most easy way for me is analyzing save game files, but on begin I need a function what can save the game for example every 10 seconds in defined path and file name.

Зачем делать сейвы каждые 10 секунд, если у плагина есть прямой доступ к структурам игры? Не лучше ли будет, если плагин создаст новое окно, в котором будет отображаться и обновляться по заданному таймеру нужная статистика. Если статистику должно отображать стороннее приложение, то плагин может, опять же по таймеру, писать данные в какой-нибудь разделяемый буфер памяти.
Вернуться к началу

offlinecatshy  
Новичок
Новичок
 
Сообщения: 15
Зарегистрирован: 06 сен 2018, 12:32
Пол: Не указан
Поблагодарили: 0 раз.

Re: Как создать плагин для HD мода

Сообщение catshy » 03 апр 2019, 14:50

AlexSpl, I dont know russian, thats why I will reply in english. You are right of course, but I dont have enought of skills to do it, thats why on begin I have to use save game files, and maybe in future I will work on a better and more efficient solution. Some time ago I tried to get the information I needed directly from the memory h3 process memory and if I did not have a problem with extracting information about cities and heroes, I had a lot of problems with the reading of objects on the map - the map is more understandable (for me) in the game's save file.

But... of course if u have a method to get this information like in save game file (about map, castles, heroes etc) without do save game process then I will be grateful :P
Последний раз редактировалось catshy 03 апр 2019, 14:55, всего редактировалось 1 раз.
Вернуться к началу

offlineBen80  
имя: Сергей
Эксперт
Эксперт
 
Сообщения: 1315
Зарегистрирован: 18 июн 2017, 06:49
Пол: Не указан
Поблагодарили: 336 раз.

Re: Как создать плагин для HD мода

Сообщение Ben80 » 03 апр 2019, 14:53

catshy писал(а):

Ben80 It would be great if you would share your code with me because the link you provided doesn't work.

Addresses for save game function in hota+hd mod will be this same (0x4BEB60 and 0x699538) as RoseKavalier wrote before?


Code which I wrote to run russian version of Armageddon's blade (one can simply change name of EXE file):
https://pastebin.com/n1rqpHsn

APIHook.pas (Berserker) contains following text:
https://pastebin.com/xUtcsA8u

Concerning compatibility between last people plugins and current HotA - it is unclear. Last plugins compatible with HotA probably was written by AlexSpl more than year ago.
Вернуться к началу

offlineBen80  
имя: Сергей
Эксперт
Эксперт
 
Сообщения: 1315
Зарегистрирован: 18 июн 2017, 06:49
Пол: Не указан
Поблагодарили: 336 раз.

Re: Как создать плагин для HD мода

Сообщение Ben80 » 03 апр 2019, 15:05

@AlexSpl - я совсем не за то, чтобы превращать форум в англоязычный, но что поделать, если наиболее активные участники форума в данный момент - англоязычные ? Кто еще, кроме RoseKavalier, вот так вот запросто может поделиться такой ценной инфой ? Из русских - AlexSpl, igrik, Berserker. Но все они в данный момент не очень активны в плане моддинга Героев 3.

@catshy - мне не удавалось запустить игру с Dll injection, если не понижал уровень безопасности операционной системы.
Вернуться к началу

offlineАватара пользователя
AlexSpl  
имя: Александр
Эксперт
Эксперт
 
Сообщения: 5547
Зарегистрирован: 17 сен 2010, 12:58
Пол: Мужчина
Награды: 14
Высшая медаль (1) Победителю турнира по HMM1_TE (2) Победителю этапа по HMM1 (1) Победителю этапа по HMM2 (1) Лучшему из лучших (1) 2 место 1 этапа по HMM1 (1)
3 место 1 этапа по HMM1 (1) 1 место 2 этапа по HMM2 (1) Победителю турнира по KB (2) Победителю турнира по KB (1) Грандмастер оффлайн-турниров (1) Боевой шлем (1)
Поблагодарили: 2162 раз.

Re: Как создать плагин для HD мода

Сообщение AlexSpl » 03 апр 2019, 19:09

2catshy: You can create an info window as shown below.

Код: Выделить всё
#define _CRT_SECURE_NO_WARNINGS
#include "HotA\homm3.h"
#include <windows.h>
#include <tchar.h>

Patcher* _P;
PatcherInstance* _PI;
static _bool_ plugin_On = 0;

#define MAX_LOADSTRING  100
TCHAR InfoClassName[MAX_LOADSTRING] = _T("H3InfoClass");

ATOM RegisterInfoClass(HINSTANCE);
LRESULT CALLBACK InfoWnd(HWND, UINT, WPARAM, LPARAM);

HINSTANCE hGameInstance;
HWND hGameWnd;
HWND hInfoWnd;

int __stdcall showInfoWnd(LoHook* h, HookContext* c)
{
    hGameWnd = *(HWND*)0x699650;
    hGameInstance = *(HINSTANCE*)0x699604;
    RegisterInfoClass(hGameInstance);

    hInfoWnd = CreateWindow(InfoClassName, _T("Info"), WS_OVERLAPPEDWINDOW,
        10, 10, 200, 400, hGameWnd, 0, hGameInstance, 0);

    ShowWindow(hInfoWnd, SW_SHOWNORMAL);
    UpdateWindow(hInfoWnd);

    return EXEC_DEFAULT;
}

ATOM RegisterInfoClass(HINSTANCE hInstance)
{
    WNDCLASSEX wcInfo = {0};

    wcInfo.cbSize = sizeof(WNDCLASSEX);

    wcInfo.style            = CS_HREDRAW | CS_VREDRAW;
    wcInfo.lpfnWndProc      = InfoWnd;
    wcInfo.cbClsExtra       = 0;
    wcInfo.cbWndExtra       = 0;
    wcInfo.hInstance        = hInstance;
    wcInfo.hIcon            = LoadIcon(wcInfo.hInstance, IDI_APPLICATION);
    wcInfo.hCursor          = LoadCursor(NULL, IDC_ARROW);
    wcInfo.hbrBackground    = (HBRUSH)(COLOR_WINDOW + 1);
    wcInfo.lpszMenuName     = NULL;
    wcInfo.lpszClassName    = InfoClassName;

    return RegisterClassEx(&wcInfo);
}

LRESULT CALLBACK InfoWnd(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;

    switch (message)
    {
        case WM_PAINT:
            hdc = BeginPaint(hWnd, &ps);
            // Here you can show info via TextOut(), for example
            EndPaint(hWnd, &ps);
            break;

        case WM_DESTROY:
            PostQuitMessage(0);
            break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
    if ( DLL_PROCESS_ATTACH == ul_reason_for_call )
    {
        if ( !plugin_On )
        {
            plugin_On = 1;
            _P = GetPatcher();
            _PI = _P->CreateInstance("HD.Plugin.InfoWnd");

            _PI->WriteLoHook(0x4F824A, showInfoWnd);
        }
    }

    return TRUE;
}
Вернуться к началу

offlinecatshy  
Новичок
Новичок
 
Сообщения: 15
Зарегистрирован: 06 сен 2018, 12:32
Пол: Не указан
Поблагодарили: 0 раз.

Re: Как создать плагин для HD мода

Сообщение catshy » 03 апр 2019, 19:42

AlexSpl, thanks for this code. Can you give me more info how to use it? where to get HotA\homm3.h and where put this compiled file?
Вернуться к началу

offlineАватара пользователя
AlexSpl  
имя: Александр
Эксперт
Эксперт
 
Сообщения: 5547
Зарегистрирован: 17 сен 2010, 12:58
Пол: Мужчина
Награды: 14
Высшая медаль (1) Победителю турнира по HMM1_TE (2) Победителю этапа по HMM1 (1) Победителю этапа по HMM2 (1) Лучшему из лучших (1) 2 место 1 этапа по HMM1 (1)
3 место 1 этапа по HMM1 (1) 1 место 2 этапа по HMM2 (1) Победителю турнира по KB (2) Победителю турнира по KB (1) Грандмастер оффлайн-турниров (1) Боевой шлем (1)
Поблагодарили: 2162 раз.

Re: Как создать плагин для HD мода

Сообщение AlexSpl » 03 апр 2019, 19:55

homm3.h is in this topic somewhere, but I'll reupload it. Later I'll show how to write info into the InfoWnd from hooks. You can either use InvalidateRect(hInfoWnd, NULL, TRUE) in hooks, or do so by means of timers (if you want to update info automatically).

* * *
HotA.zip
(65.29 КБ) Скачиваний: 588
Вернуться к началу

offlinecatshy  
Новичок
Новичок
 
Сообщения: 15
Зарегистрирован: 06 сен 2018, 12:32
Пол: Не указан
Поблагодарили: 0 раз.

Re: Как создать плагин для HD мода

Сообщение catshy » 03 апр 2019, 21:15

AlexSpl thanks for upload... but I cant compile it, Im using Microsoft Visual C++ 2010 Express and when I make a new project with your code and HotA files I have a lot of errors. And second question, I should compile it as exe or as dll? and if as dll how I should use it into h3 hota + hd mod, should do I dll injection?
Вернуться к началу

offlineRoseKavalier  
Мастер
Мастер
 
Сообщения: 331
Зарегистрирован: 23 сен 2017, 17:00
Пол: Не указан
Поблагодарили: 234 раз.

Re: Как создать плагин для HD мода

Сообщение RoseKavalier » 04 апр 2019, 03:43

@catshy
1\ Alex's code seems fine at a glance, of course incomplete but it should do ok.
Now nobody can magically guess what is wrong on your end, it's like you went to car mechanic and told him "there is problem with my car" and left.
Is it the engine? The wheels? There is no gas in the tank?
Be specific! What errors are you getting?

BTW, my guess would be #include path is not correctly set. :smile6:

2\ Plugins discussed here are DLLs that are injected into the game exe. You can also make an exe that will read RAM and get relevant information from Heroes 3. I've had bad experience with EXE as they have a habit of stopping to work every few HDmod updates and then you have to recompile over and over, whereas a well programmed DLL that is injected has little chance of breaking in the future.
Alex has considerable experience on this (see LMOracle), he can answer better than I ever will.

3\ wrt your last question, I would suggest to ignore HotA for now and start working in SoD. The HDmod allows for easy injection in SoD so you don't have to worry about this part right away while you learn how to do the things you are looking for.
Once your plugin works in SoD, HotA will be 99.9% the same, with maybe a few differences to be accounted for depending on what statistics you are looking to display. At this point only it'll be time to worry about injection into HotA exe.
Baby steps eventually lead to running :smile1:

@Ben80
Your comment about shifted blocks has got me thinking about potential fix to a lot of issues. I think a big part of RMG problems is zones that are not correctly closed by obstacles but blocked off by creatures. This leads to roads going in the wrong direction and all kinds of problems. It is likely that the core of the solution to enhance RMG lies in fixing sub_00541630 or a similar function responsible for delimitation of connected zones by roads.
Food for thought.

Sorry about my non-Russian posts, I've been told on HW it's better I write in English than try through translator :smile5:
I could make effort to learn a bit but it probably be worse than translator)
Вернуться к началу

offlineBen80  
имя: Сергей
Эксперт
Эксперт
 
Сообщения: 1315
Зарегистрирован: 18 июн 2017, 06:49
Пол: Не указан
Поблагодарили: 336 раз.

Re: Как создать плагин для HD мода

Сообщение Ben80 » 04 апр 2019, 04:40

RoseKavalier писал(а):

@Ben80
Your comment about shifted blocks has got me thinking about potential fix to a lot of issues. I think a big part of RMG problems is zones that are not correctly closed by obstacles but blocked off by creatures. This leads to roads going in the wrong direction and all kinds of problems. It is likely that the core of the solution to enhance RMG lies in fixing sub_00541630 or a similar function responsible for delimitation of connected zones by roads.
Food for thought.


At this moment I have following solutions (unfortunately right now I can not write corresponding code and make Dll):

1) Simple solution for shifted passage guards, which fixes 90% cases. For more advanced solution it would be useful to know which code cut some objects between zones to make path (I hoped this code in sub_00541630, but it seems not)

Изображение

2a) Checking for wrong connections between zones (people say that it is frequently occur when mines placed in zones). So, probably it is related to incorrect cutting-off objects between zones. So, again, in which code it occurs ?
I don't know. So, at this moment solution is regenerate map (such cases are quite rare).
2b) Checking for deadlocks between zones instead of connections. Is this related to sub_00541630 ? For example function returns non-zero, but actually some objects are not deleted ? So, there is no path.
Again, such cases are rare and one can regerate map.

So, at this moment my solutions are very "post-processing". It would be good to make solutions more thin and elegant.

Other thoughts I will write a bit later :smile1:
Вернуться к началу

Пред.След.

Вернуться в Общий раздел

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 2