Advertisement
Guest User

mapeditor

a guest
Jul 10th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.65 KB | None | 0 0
  1. #include <windows.h>
  2. #include "..\..\include\patcher_x86_commented.hpp"
  3.  
  4.  
  5. Patcher * globalPatcher;
  6. PatcherInstance *patcher;
  7.  
  8. struct _TownBuildingInfo_
  9. {
  10.     char* short_name;
  11.     char* long_name;
  12.     int prerequisit;
  13. };
  14.  
  15.  
  16. #define o_KnightBuildings       ((_TownBuildingInfo_*)0x005A6458)
  17. #define o_SorcBuildings         ((_TownBuildingInfo_*)0x005A7830)
  18. #define o_WizardBuildings       ((_TownBuildingInfo_*)0x005A6860)
  19. #define o_HereticBuildings      ((_TownBuildingInfo_*)0x005A6240)
  20. #define o_WarlockBuildings      ((_TownBuildingInfo_*)0x005A71D0)
  21. #define o_NecromancyBuildings   ((_TownBuildingInfo_*)0x005A75F0)
  22. #define o_BarbarianBuildings    ((_TownBuildingInfo_*)0x005A6AE0)
  23. #define o_WitchBuildings        ((_TownBuildingInfo_*)0x005A6F30)
  24. #define o_DervishBuildings      ((_TownBuildingInfo_*)0x005A6D10)
  25. #define o_RandomBuildings       ((_TownBuildingInfo_*)0x005A6660)
  26.  
  27.  
  28. #define ME_TOWN_HALL        0
  29. #define ME_CITY_HALL        1
  30. #define ME_CAPITOL          2
  31. #define ME_FORT             3
  32. #define ME_CITADEL          4
  33. #define ME_CASTLE           5
  34. #define ME_TAVERN           6
  35. #define ME_BLACKMITH        7
  36. #define ME_MARKETPLACE      8
  37. #define ME_SILO             9
  38. #define ME_ART_MERCHANT     10
  39. #define ME_MAGE_GUILD_1     11
  40. #define ME_MAGE_GUILD_2     12
  41. #define ME_MAGE_GUILD_3     13
  42. #define ME_MAGE_GUILD_4     14
  43. #define ME_MAGE_GUILD_5     15
  44. #define ME_SHIPYARD         16
  45. #define ME_GRAIL            17
  46. #define ME_SPEC1            18  //
  47. #define ME_SPEC2            19
  48. #define ME_SPEC3            20
  49. #define ME_SPEC4            21
  50. #define ME_DWELL1           22
  51. #define ME_DWELL1_UP        23
  52. #define ME_DWELL1_HORDE     24
  53. #define ME_DWELL2           25
  54. #define ME_DWELL2_UP        26
  55. #define ME_DWELL2_HORDE     27
  56. #define ME_DWELL3           28
  57. #define ME_DWELL3_UP        29
  58. #define ME_DWELL3_HORDE     30
  59. #define ME_DWELL4           31
  60. #define ME_DWELL4_UP        32
  61. #define ME_DWELL4_HORDE     33
  62. #define ME_DWELL5           34
  63. #define ME_DWELL5_UP        35
  64. #define ME_DWELL5_HORDE     36
  65. #define ME_DWELL6           37
  66. #define ME_DWELL6_UP        38
  67. #define ME_DWELL7           39
  68. #define ME_DWELL7_UP        40
  69.  
  70. void CopyBuildingInformation(_TownBuildingInfo_* source, _TownBuildingInfo_* destination)
  71. {
  72.     source->short_name  = destination->short_name;
  73.     source->long_name   = destination->long_name;
  74.     source->prerequisit = destination->prerequisit;
  75. }
  76.  
  77. void DisableBuilding(_TownBuildingInfo_* source)
  78. {
  79.     source->short_name  = 0;
  80.     source->long_name   = 0;
  81.     source->prerequisit = -1;
  82. }
  83.  
  84. void FlattenBuildingsPrereqs(_TownBuildingInfo_* source)
  85. {
  86.     source->prerequisit = -1;
  87. }
  88.  
  89. void __stdcall OnTownsLoad(HiHook* h)
  90. {
  91.     CALL_0(void, __stdcall, h->GetDefaultFunc());
  92.  
  93.     //MageGuilds
  94.     CopyBuildingInformation(o_KnightBuildings + ME_MAGE_GUILD_5,        o_WarlockBuildings + ME_MAGE_GUILD_5);
  95.     CopyBuildingInformation(o_WitchBuildings + ME_MAGE_GUILD_4,         o_WarlockBuildings + ME_MAGE_GUILD_4);
  96.     CopyBuildingInformation(o_WitchBuildings + ME_MAGE_GUILD_5,         o_WarlockBuildings + ME_MAGE_GUILD_5);
  97.     CopyBuildingInformation(o_BarbarianBuildings + ME_MAGE_GUILD_4,     o_WarlockBuildings + ME_MAGE_GUILD_4);
  98.     CopyBuildingInformation(o_BarbarianBuildings + ME_MAGE_GUILD_5,     o_WarlockBuildings + ME_MAGE_GUILD_5);
  99.  
  100.     CopyBuildingInformation(o_SorcBuildings + ME_SHIPYARD,      o_KnightBuildings + ME_SHIPYARD);
  101.     CopyBuildingInformation(o_WizardBuildings + ME_SHIPYARD,    o_KnightBuildings + ME_SHIPYARD);
  102.     CopyBuildingInformation(o_BarbarianBuildings + ME_SHIPYARD, o_KnightBuildings + ME_SHIPYARD);
  103.     CopyBuildingInformation(o_WarlockBuildings + ME_SHIPYARD,   o_KnightBuildings + ME_SHIPYARD);
  104.     CopyBuildingInformation(o_HereticBuildings + ME_SHIPYARD,   o_KnightBuildings + ME_SHIPYARD);
  105.  
  106.     /*DisableBuilding(o_KnightBuildings     + ME_GRAIL);
  107.     DisableBuilding(o_SorcBuildings         + ME_GRAIL);
  108.     DisableBuilding(o_WizardBuildings       + ME_GRAIL);
  109.     DisableBuilding(o_HereticBuildings      + ME_GRAIL);
  110.     DisableBuilding(o_NecromancyBuildings   + ME_GRAIL);
  111.     DisableBuilding(o_WarlockBuildings      + ME_GRAIL);
  112.     DisableBuilding(o_BarbarianBuildings    + ME_GRAIL);
  113.     DisableBuilding(o_WitchBuildings        + ME_GRAIL);
  114.     DisableBuilding(o_DervishBuildings      + ME_GRAIL);*/
  115.  
  116.  
  117.     _TownBuildingInfo_* allfractions[] = {o_KnightBuildings, o_SorcBuildings, o_WizardBuildings,
  118.                             o_HereticBuildings, o_NecromancyBuildings, o_WarlockBuildings,
  119.                             o_BarbarianBuildings, o_WitchBuildings, o_DervishBuildings,
  120.                             o_RandomBuildings};
  121.     int dwells[] = {ME_DWELL1, ME_DWELL2, ME_DWELL3, ME_DWELL4, ME_DWELL5, ME_DWELL6, ME_DWELL7};
  122.  
  123.     for(int i = 0; i!=10; i++)
  124.     {
  125.         DisableBuilding(allfractions[i]+ME_GRAIL);
  126.         for(int j = 0; j!=7; j++)
  127.         {
  128.             FlattenBuildingsPrereqs(allfractions[i]+dwells[j]);
  129.         }  
  130.     }
  131.  
  132.     //Fortifications
  133.     DisableBuilding(o_KnightBuildings       + ME_SPEC1);
  134.     //Lookout Tower
  135.     DisableBuilding(o_WizardBuildings       + ME_SPEC3);
  136.     //Mirage
  137.     DisableBuilding(o_DervishBuildings      + ME_SPEC1);
  138.  
  139.     //Rainbow
  140.     o_SorcBuildings[ME_SPEC2].prerequisit = -1;
  141.     //Treasury
  142.     o_SorcBuildings[ME_SPEC3].prerequisit = ME_CITADEL;
  143.     //Crystal Garden
  144.     o_SorcBuildings[ME_DWELL5_HORDE].prerequisit = ME_DWELL1;
  145.  
  146.     //Orchard
  147.     o_WizardBuildings[ME_DWELL2_HORDE].prerequisit = ME_DWELL1;
  148.  
  149.     //Black tower
  150.     o_WarlockBuildings[ME_SPEC2].prerequisit = ME_DWELL7_UP;
  151.  
  152.     //Upgrades
  153.     DisableBuilding(o_KnightBuildings       + ME_DWELL1_UP);
  154.  
  155.     DisableBuilding(o_SorcBuildings     + ME_DWELL1_UP);
  156.     DisableBuilding(o_SorcBuildings     + ME_DWELL2_HORDE);
  157.     DisableBuilding(o_SorcBuildings     + ME_DWELL4_UP);
  158.     DisableBuilding(o_SorcBuildings     + ME_DWELL6_UP);
  159.     DisableBuilding(o_SorcBuildings     + ME_DWELL7_UP);
  160.    
  161.     DisableBuilding(o_WizardBuildings + ME_DWELL1_UP);
  162.     DisableBuilding(o_WizardBuildings + ME_DWELL2_UP);
  163.     DisableBuilding(o_WizardBuildings + ME_DWELL3_UP);
  164.     DisableBuilding(o_WizardBuildings + ME_DWELL5_UP);
  165.  
  166.     DisableBuilding(o_NecromancyBuildings + ME_DWELL1_UP);
  167.     DisableBuilding(o_NecromancyBuildings + ME_DWELL5_UP);
  168.     DisableBuilding(o_NecromancyBuildings + ME_DWELL7_UP);
  169.  
  170.     DisableBuilding(o_WarlockBuildings + ME_DWELL1_UP);
  171.     DisableBuilding(o_WarlockBuildings + ME_DWELL2_UP);
  172.     DisableBuilding(o_WarlockBuildings + ME_DWELL3_UP);
  173.     DisableBuilding(o_WarlockBuildings + ME_DWELL4_UP);
  174.     DisableBuilding(o_WarlockBuildings + ME_DWELL6_UP);
  175.    
  176.     DisableBuilding(o_BarbarianBuildings + ME_DWELL1_UP);
  177.     DisableBuilding(o_BarbarianBuildings + ME_DWELL3_UP);
  178.     DisableBuilding(o_BarbarianBuildings + ME_DWELL4_UP);
  179.     DisableBuilding(o_BarbarianBuildings + ME_DWELL7_UP);
  180.    
  181.     DisableBuilding(o_WitchBuildings + ME_DWELL1_UP);
  182.     DisableBuilding(o_WitchBuildings + ME_DWELL2_UP);
  183.     DisableBuilding(o_WitchBuildings + ME_DWELL4_UP);
  184.     DisableBuilding(o_WitchBuildings + ME_DWELL5_UP);
  185.     DisableBuilding(o_WitchBuildings + ME_DWELL6_UP);
  186.     DisableBuilding(o_WitchBuildings + ME_DWELL7_UP);
  187.    
  188.     DisableBuilding(o_DervishBuildings + ME_DWELL2_UP);
  189.     DisableBuilding(o_DervishBuildings + ME_DWELL3_UP);
  190.     DisableBuilding(o_DervishBuildings + ME_DWELL5_UP);
  191.     DisableBuilding(o_DervishBuildings + ME_DWELL6_UP);
  192.     DisableBuilding(o_DervishBuildings + ME_DWELL7_UP);
  193.     //005A6240 - heretic
  194.     //005A6458 - castle
  195.     //005A6660 - random
  196.     //005A6860 - wizard
  197.     //005A6AE0 - barbarian
  198.     //005A6D10 - dervish
  199.     //005A6F30 - witch
  200.     //005A71D0 - warlock4
  201.     //005A75F0 - necromancer
  202.     //005A7830 - sorc
  203.  
  204.     //005A6240
  205. }
  206.  
  207.  
  208.  
  209. void __stdcall ColorCycle(HiHook* h, int th, int _1, int _2, int _3)
  210. {
  211.     CALL_4(void, __thiscall, h->GetDefaultFunc(), th, 0xEC, 0xED, -1);
  212.     CALL_4(void, __thiscall, h->GetDefaultFunc(), th, 0xE7, 0xEB, -1);
  213.     CALL_4(void, __thiscall, h->GetDefaultFunc(), th, 0xD6, 0xD9, -1);  
  214. }
  215.  
  216.  
  217. void __stdcall ColorCycleNOP(HiHook* h, int th, int _1, int _2, int _3)
  218. {  
  219. }
  220.  
  221.  
  222. BOOL APIENTRY DllMain( HMODULE hModule,
  223.                        DWORD  ul_reason_for_call,
  224.                        LPVOID lpReserved
  225.                      )
  226. {
  227.     if (ul_reason_for_call == DLL_PROCESS_ATTACH)
  228.     {
  229.         globalPatcher = GetPatcher();
  230.         patcher =  globalPatcher->CreateInstance("h2sw_mapeditor");
  231.  
  232.        
  233.         patcher->WriteHiHook(0x4CB57C, SPLICE_, EXTENDED_, STDCALL_, OnTownsLoad);
  234.  
  235.        
  236.         patcher->WriteHiHook(0x4BE88C, CALL_, EXTENDED_, THISCALL_, ColorCycle); //water 0xE5, 0xF0, -1
  237.         patcher->WriteHiHook(0x4BE89E, CALL_, EXTENDED_, THISCALL_, ColorCycleNOP); //water 0xF2, 0xFD, -1
  238.  
  239.         //patcher->WriteHiHook(0x4BE8C5, CALL_, EXTENDED_, THISCALL_, ColorCycle); //lavatl 0xF6, 0xFE, -1
  240.  
  241.         patcher->WriteHiHook(0x4BE8DD, CALL_, EXTENDED_, THISCALL_, ColorCycle); //clrrvr 0xB7, 0xC2, -1
  242.         patcher->WriteHiHook(0x4BE8FE, CALL_, EXTENDED_, THISCALL_, ColorCycleNOP); //clrrvr 0xC3, 0xC8, -1
  243.  
  244.         //patcher->WriteHiHook(0x4BE916, CALL_, EXTENDED_, THISCALL__, ColorCycle6); //mudrvr 0xE4, 0xEF, -1
  245.         //patcher->WriteHiHook(0x4BE928, CALL_, EXTENDED_, THISCALL__, ColorCycle7); //mudrvr 0xB7, 0xBC, -1
  246.         //patcher->WriteHiHook(0x4BE936, CALL_, EXTENDED_, THISCALL__, ColorCycle8); //mudrvr 0xF0, 0xF5, -1
  247.  
  248.         //patcher->WriteHiHook(0x4BE94B, CALL_, EXTENDED_, THISCALL_, ColorCycle); //lavrvr 0xF0, 0xF8, -1
  249.        
  250.     }
  251.     return TRUE;
  252. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement