diff --git a/Maps/lua.w3m b/Maps/lua.w3m deleted file mode 100644 index 6e7ef83..0000000 Binary files a/Maps/lua.w3m and /dev/null differ diff --git a/README.md b/README.md index eb23eb6..6778b25 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# War3 Lua - 1.1.5 (Ashenvale - Experimental) +# War3 Lua - 1.1.6 (Outland) [![build](https://github.com/Ev3nt/war3_lua/actions/workflows/build.yml/badge.svg)](https://github.com/Ev3nt/war3_lua/actions/workflows/build.yml) @@ -6,6 +6,8 @@ War3 Lua is a modification that allows you to run lua scripts at the JASS level. Some natives doesn't work (thx jass for beautiful VM). +Lua version: **5.4.4** + ![](https://github.com/Ev3nt/war3_lua/blob/master/war3_lua.png) --- @@ -23,5 +25,5 @@ Some natives doesn't work (thx jass for beautiful VM). ### Recommended build parameters * Configuration **Release** * Windows platform **x86** -* Platform **10.0.19041.0** +* Platform **10.0.19041.**0**** * Build tools **Visual Studio 2015 (v140)** diff --git a/Scripts/blizzard.lua b/Scripts/blizzard.lua index 212578b..797b5b6 100644 --- a/Scripts/blizzard.lua +++ b/Scripts/blizzard.lua @@ -9823,7 +9823,7 @@ function InitBlizzardGlobals() end bj_FORCE_ALL_PLAYERS = CreateForce() - ForceEnumPlayers(bj_FORCE_ALL_PLAYERS, 0) + ForceEnumPlayers(bj_FORCE_ALL_PLAYERS, nil) -- Init Cinematic Mode history bj_cineModePriorSpeed = GetGameSpeed() @@ -9897,17 +9897,17 @@ function InitSummonableCaps() -- upgraded units -- Note: Only do this if the corresponding upgrade is not yet researched -- Barrage - Siege Engines - if (not GetPlayerTechResearched(Player(index), 'Rhrt', true)) then - SetPlayerTechMaxAllowed(Player(index), 'hrtt', 0) + if (not GetPlayerTechResearched(Player(index), StringToId('Rhrt'), true)) then + SetPlayerTechMaxAllowed(Player(index), StringToId('hrtt'), 0) end -- Berserker Upgrade - Troll Berserkers - if (not GetPlayerTechResearched(Player(index), 'Robk', true)) then - SetPlayerTechMaxAllowed(Player(index), 'otbk', 0) + if (not GetPlayerTechResearched(Player(index), StringToId('Robk'), true)) then + SetPlayerTechMaxAllowed(Player(index), StringToId('otbk'), 0) end -- max skeletons per player - SetPlayerTechMaxAllowed(Player(index), 'uske', bj_MAX_SKELETONS) + SetPlayerTechMaxAllowed(Player(index), StringToId('uske'), bj_MAX_SKELETONS) index = index + 1 if index == bj_MAX_PLAYERS then break end @@ -10046,7 +10046,7 @@ function InitNeutralBuildings() -- Set up a trigger to fire whenever an item is sold. bj_stockItemPurchased = CreateTrigger() - TriggerRegisterPlayerUnitEvent(bj_stockItemPurchased, Player(PLAYER_NEUTRAL_PASSIVE), EVENT_PLAYER_UNIT_SELL_ITEM, 0) + TriggerRegisterPlayerUnitEvent(bj_stockItemPurchased, Player(PLAYER_NEUTRAL_PASSIVE), EVENT_PLAYER_UNIT_SELL_ITEM, nil) TriggerAddAction(bj_stockItemPurchased, RemovePurchasedItem) end -- =========================================================================== @@ -10218,37 +10218,6 @@ end -- -- *************************************************************************** --- function GetEffectPos(effect) --- return GetObjectPos(effect) --- end - --- function GetEffectX(effect) --- return GetObjectX(effect) --- end - --- function GetEffectY(effect) --- return GetObjectY(effect) --- end - --- function GetEffectZ(effect) --- return GetObjectZ(effect) --- end - --- function SetEffectPos(effect, x, y, z) --- SetObjectPos(effect, x, y, z) --- end - --- function SetEffectX(effect, x) --- SetObjectX(effect, x) --- end - --- function SetEffectY(effect, y) --- SetObjectY(effect, y) --- end --- function SetEffectZ(effect, z) --- SetObjectZ(effect, z) --- end - function _print(...) local string = "" diff --git a/Scripts/common.lua b/Scripts/common.lua index f0b6ec6..76666c0 100644 --- a/Scripts/common.lua +++ b/Scripts/common.lua @@ -1,6 +1,6 @@ FALSE = false TRUE = true -JASS_MAX_ARRAY_SIZE = 32768 +JASS_MAX_ARRAY_SIZE = 8192 PLAYER_NEUTRAL_PASSIVE = 15 PLAYER_NEUTRAL_AGGRESSIVE = 12 PLAYER_COLOR_RED = ConvertPlayerColor(0) diff --git a/Src Backup/.vscode/settings.json b/Src Backup/.vscode/settings.json deleted file mode 100644 index 6f26099..0000000 --- a/Src Backup/.vscode/settings.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "files.associations": { - "map": "cpp", - "bit": "cpp", - "compare": "cpp", - "concepts": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "cwchar": "cpp", - "exception": "cpp", - "initializer_list": "cpp", - "limits": "cpp", - "new": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "vector": "cpp", - "xmemory": "cpp", - "xstddef": "cpp", - "xtr1common": "cpp", - "xtree": "cpp", - "xutility": "cpp" - } -} \ No newline at end of file diff --git a/Src Backup/FrameAPI.cpp b/Src Backup/FrameAPI.cpp deleted file mode 100644 index b99317b..0000000 --- a/Src Backup/FrameAPI.cpp +++ /dev/null @@ -1,158 +0,0 @@ -#include "FrameAPI.h" -#include "Variables.h" -#include "fcalls.h" - -std::unordered_map> frameEventHashTable; - -UINT GetOriginFrame(EOriginFrame originframe, UINT index) { - CGameUI* gameui = GetGameUI(); - - switch (originframe) { - case ORIGIN_FRAME_GAME_UI: - return (UINT)gameui; - case ORIGIN_FRAME_WORLD_FRAME: - return (UINT)gameui->WorldFrameWar3; - case ORIGIN_FRAME_HERO_BAR: - return (UINT)gameui->HeroBar; - case ORIGIN_FRAME_HERO_BUTTON: - return (UINT)GetPanelButton((UINT)gameui->HeroBar, index, 0); - case ORIGIN_FRAME_HERO_HP_BAR: - return *(UINT*)((UINT)GetPanelButton((UINT)gameui->HeroBar, index, 0) + 0x1cc); - case ORIGIN_FRAME_HERO_MANA_BAR: - return *(UINT*)((UINT)GetPanelButton((UINT)gameui->HeroBar, index, 0) + 0x1d0); - case ORIGIN_FRAME_HERO_BUTTON_INDICATOR: - // Undefined - break; - case ORIGIN_FRAME_ITEM_BUTTON: - return *(UINT*)(*(UINT*)(*(UINT*)(gameui->InfoBar + 0x148) + 0x130) + 8 * index + 4); - case ORIGIN_FRAME_COMMAND_BUTTON: - return (UINT)GetPanelButton((UINT)gameui->CommandBar, index / 4, index % 4); - case ORIGIN_FRAME_SYSTEM_BUTTON: - // Undefined - break; - case ORIGIN_FRAME_PORTRAIT: - return (UINT)gameui->Portrait; - case ORIGIN_FRAME_MINIMAP: - return (UINT)gameui->Minimap; - case ORIGIN_FRAME_MINIMAP_BUTTON: - return (UINT)gameui->MinimapButtons[index]; - case ORIGIN_FRAME_TOOLTIP: - return GetTooltipFrame(); - case ORIGIN_FRAME_UBERTOOLTIP: - // Undefined - break; - case ORIGIN_FRAME_CHAT_MSG: - return (UINT)gameui->ChatMessage; - case ORIGIN_FRAME_UNIT_MSG: - return (UINT)gameui->UnitMessage; - case ORIGIN_FRAME_TOP_MSG: - return (UINT)gameui->TopMessage; - default: - break; - } - - return NULL; -} - -UINT GetPanelButton(UINT frame, BYTE row, BYTE column) { - return *(UINT*)(*(DWORD*)(16 * row + *((DWORD*)frame + 85) + 8) + 4 * column) - sizeof(CFrame); -} - -UINT GetTooltipFrame(UINT unknown0) { - return fastcall(MakePtr(gameBase, _getTooltipFrame), unknown0); -} - -BOOL LoadTOCFile(LPCSTR filename) { - DWORD stringHastTable = MakePtr(gameBase, _stringHastTable); - DWORD FDFHashTable = MakePtr(gameBase, _FDFHashTable); - - if (*(int*)(stringHastTable + 0x14) < 0xFFFF) { - thiscall(MakePtr(gameBase, _stringHashNodeGrowListArray), stringHastTable, 0xFFFF); - } - - if (*(int*)(FDFHashTable + 0x14) < 0xFFFF) { - thiscall(MakePtr(gameBase, _baseFrameHashNodeGrowListArray), FDFHashTable, 0xFFFF); - } - - return fastcall(MakePtr(gameBase, _readFDFFile), filename, stringHastTable, FDFHashTable, MakePtr(gameBase, _CFrameDefStatus)); -} - -UINT GetFrameByName(LPCSTR framename, UINT id) { - return fastcall(MakePtr(gameBase, _getCFrameByName), framename, id); -} - -UINT CreateFrame(LPCSTR baseframe, UINT parentframe, EFramePoint point, EFramePoint relativepoint, UINT id) { - return fastcall(MakePtr(gameBase, _createCFrame), baseframe, parentframe, point, relativepoint, id); -} - -void SetFrameText(UINT frame, LPCSTR text) { - thiscall(MakePtr(gameBase, _setCFrameText), *(UINT*)(FRAMELAYOUT(frame) + 0x130), text); -} - -void SetFrameTextColor(UINT frame, BYTE red, BYTE green, BYTE blue, BYTE alpha) { - DWORD color = ((alpha << 24) + (red << 16) + (green << 8) + blue); - thiscall(MakePtr(gameBase, _setCFrameTextColor), FRAMELAYOUT(frame), &color); -} - -float GetFrameTextHeight(UINT frame) { - return thiscall(MakePtr(gameBase, _getCFrameTextHeight), FRAMELAYOUT(frame)); -} - -void SetFrameWidth(UINT frame, float width) { - thiscall(MakePtr(gameBase, _setCLayoutFrameWidth), FRAMELAYOUT(frame), width); -} - -void SetFrameHeight(UINT frame, float height) { - thiscall(MakePtr(gameBase, _setCLayoutFrameHeight), FRAMELAYOUT(frame), height); -} - -void SetFrameSize(UINT frame, float width, float height) { - SetFrameWidth(frame, width); - SetFrameHeight(frame, height); -} - -void SetFrameScale(UINT frame, float scale) { - thiscall(MakePtr(gameBase, _setCLayoutFrameScale), FRAMELAYOUT(frame), scale); -} - -void SetFrameAbsolutePoint(UINT frame, EFramePoint point, float offsetX, float offsetY) { - thiscall(MakePtr(gameBase, _setCLayoutFrameAbsolutePoint), FRAMELAYOUT(frame), point, offsetX, offsetY, 1); -} - -void SetFramePoint(UINT frame, EFramePoint point, UINT parentframe, EFramePoint relativepoint, float offsetX, float offsetY) { - thiscall(MakePtr(gameBase, _setCLayoutFramePoint), FRAMELAYOUT(frame), point, FRAMELAYOUT(parentframe), relativepoint, offsetX, offsetY, 1); -} - -float GetFrameWidth(UINT frame) { - return *(float*)(FRAMELAYOUT(frame) + 0x58); -} - -float GetFrameHeight(UINT frame) { - return *(float*)(FRAMELAYOUT(frame) + 0x5c); -} - -UINT GetFramePoint(UINT frame, EFramePoint point) { - return *(UINT*)(FRAMELAYOUT(frame) + 4 * (UINT)point + 8); -} - -UINT GetFramePointParent(UINT frame, EFramePoint point) { - return *(UINT*)(GetFramePoint(frame, point) + 4); -} - -UINT GetFramePointRelativePoint(UINT frame, EFramePoint point) { - return *(UINT*)(GetFramePoint(frame, point) + 8); -} - -float GetFramePointX(UINT frame, EFramePoint point) { - return *(float*)(GetFramePoint(frame, point) + 12); -} - -float GetFramePointY(UINT frame, EFramePoint point) { - return *(float*)(GetFramePoint(frame, point) + 16); -} - -//--------------------------------------------------------------------------------------- - -void TriggerRegisterFrameEvent(UINT trigger, UINT frame, EFrameEvent event) { - frameEventHashTable[event][frame] = trigger; -} \ No newline at end of file diff --git a/Src Backup/FrameAPI.h b/Src Backup/FrameAPI.h deleted file mode 100644 index 49effa2..0000000 --- a/Src Backup/FrameAPI.h +++ /dev/null @@ -1,105 +0,0 @@ -#pragma once - -#include "Warcraft.h" -#include "Mem.h" - -enum EFramePoint : UINT -{ - TopLeft = 0, - Top = 1, - TopRight = 2, - Left = 3, - Center = 4, - Right = 5, - BottomLeft = 6, - Bottom = 7, - BottomRight = 8 -}; - -enum EOriginFrame : UINT { - ORIGIN_FRAME_GAME_UI, - ORIGIN_FRAME_WORLD_FRAME, - ORIGIN_FRAME_HERO_BAR, - ORIGIN_FRAME_HERO_BUTTON, - ORIGIN_FRAME_HERO_HP_BAR, - ORIGIN_FRAME_HERO_MANA_BAR, - ORIGIN_FRAME_HERO_BUTTON_INDICATOR, - ORIGIN_FRAME_ITEM_BUTTON, - ORIGIN_FRAME_COMMAND_BUTTON, - ORIGIN_FRAME_SYSTEM_BUTTON, - ORIGIN_FRAME_PORTRAIT, - ORIGIN_FRAME_MINIMAP, - ORIGIN_FRAME_MINIMAP_BUTTON, - ORIGIN_FRAME_TOOLTIP, - ORIGIN_FRAME_UBERTOOLTIP, - ORIGIN_FRAME_CHAT_MSG, - ORIGIN_FRAME_UNIT_MSG, - ORIGIN_FRAME_TOP_MSG -}; - -enum EFrameEvent : UINT { - FRAMEEVENT_CONTROL_CLICK = 1, - FRAMEEVENT_MOUSE_ENTER, - FRAMEEVENT_MOUSE_LEAVE, - FRAMEEVENT_MOUSE_UP, - FRAMEEVENT_MOUSE_DOWN, - FRAMEEVENT_MOUSE_WHEEL, - FRAMEEVENT_CHECKBOX_CHECKED, - FRAMEEVENT_CHECKBOX_UNCHECKED, - FRAMEEVENT_EDITBOX_TEXT_CHANGED, - FRAMEEVENT_POPUPMENU_ITEM_CHANGED, - FRAMEEVENT_MOUSE_DOUBLECLICK, - FRAMEEVENT_SPRITE_ANIM_UPDATE, - FRAMEEVENT_SLIDER_VALUE_CHANGED, - FRAMEEVENT_DIALOG_CANCEL, - FRAMEEVENT_DIALOG_ACCEPT, - FRAMEEVENT_EDITBOX_ENTER -}; - -//DWORD eventType[16] = {MakePtr(gameBase, _frameevent_control_click), MakePtr(gameBase, _frameevent_control_mouseenter) }; - -UINT GetOriginFrame(EOriginFrame originframe, UINT index); - -UINT GetPanelButton(UINT frame, BYTE row, BYTE column); - -UINT GetTooltipFrame(UINT unknown0 = NULL); - -BOOL LoadTOCFile(LPCSTR filename); - -UINT GetFrameByName(LPCSTR framename, UINT id); - -UINT CreateFrame(LPCSTR baseframe, UINT parentframe, EFramePoint point, EFramePoint relativepoint, UINT id); - -void SetFrameText(UINT frame, LPCSTR text); - -void SetFrameTextColor(UINT frame, BYTE red, BYTE green, BYTE blue, BYTE alpha); - -float GetFrameTextHeight(UINT frame); - -void SetFrameWidth(UINT frame, float width); - -void SetFrameHeight(UINT frame, float height); - -void SetFrameSize(UINT frame, float width, float height); - -void SetFrameScale(UINT frame, float scale); - -void SetFrameAbsolutePoint(UINT frame, EFramePoint point, float offsetX, float offsetY); - -void SetFramePoint(UINT frame, EFramePoint point, UINT parentframe, EFramePoint relativepoint, float offsetX, float offsetY); - -float GetFrameWidth(UINT frame); - -float GetFrameHeight(UINT frame); - -UINT GetFramePointParent(UINT frame, EFramePoint point); - -UINT GetFramePointRelativePoint(UINT frame, EFramePoint point); - -float GetFramePointX(UINT frame, EFramePoint point); - -float GetFramePointY(UINT frame, EFramePoint point); - -//--------------------------------------------------------------------------------------- - -void TriggerRegisterFrameEvent(UINT trigger, UINT frame, EFrameEvent event); \ No newline at end of file diff --git a/Src Backup/Hooks.cpp b/Src Backup/Hooks.cpp deleted file mode 100644 index da1cfa1..0000000 --- a/Src Backup/Hooks.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "Hooks.h" - -#include "Variables.h" -#include "Mem.h" -#include "LuaMachine.h" -#include - -DWORD __fastcall jassEntryPoint(DWORD a) { - return (fastcall(MakePtr(gameBase, _jassEntryPointProc), a), startLua()); -} - -DWORD __stdcall getWarcraftID() -{ - return *(DWORD*)GAME_ID; -} - -BOOL __fastcall isFrameValid(UINT frame, UINT, UINT eventcode) { - for (const auto& event : frameEventHashTable) { - for (const auto& eventframe : event.second) { - if (eventframe.first == frame) { - // our code - - return TRUE; - } - } - } - - if (!*(DWORD*)(frame + 8)) { - return FALSE; - } - - return thiscall(MakePtr(gameBase, 0x62a1c0), *(DWORD*)(frame + 8), eventcode, 0); -} - -BOOL __fastcall frameEventObserver(UINT frame, UINT, DWORD eventaddress) { - if (frameEventHashTable[(EFrameEvent)(*(DWORD*)(eventaddress + 8) - 0x40090063)].find(frame) != frameEventHashTable[(EFrameEvent)(*(DWORD*)(eventaddress + 8) - 0x40090063)].end()) { - if (!running) { - return FALSE; - } - - lua_State* l = getMainLuaState(); - getFunctionByRef(l, frameEventHashTable[(EFrameEvent)(*(DWORD*)(eventaddress + 8) - 0x40090063)][frame]); - lua_State* thread = createThread(l, -1); - lua_xmove(l, thread, 1); - - int res; - switch (lua_resume(thread, l, 0, &res)) { - case LUA_ERRRUN: - lua_throwerr(thread); - - break; - } - - return TRUE; - } - - return thiscall(*(DWORD*)(*(DWORD*)frame + 0x14), frame, *(DWORD*)(eventaddress + 8), eventaddress); -} \ No newline at end of file diff --git a/Src Backup/Hooks.h b/Src Backup/Hooks.h deleted file mode 100644 index 19103cf..0000000 --- a/Src Backup/Hooks.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include - -DWORD __fastcall jassEntryPoint(DWORD a); - -DWORD __stdcall getWarcraftID(); - -BOOL __fastcall isFrameValid(UINT frame, UINT, UINT eventcode); - -BOOL __fastcall frameEventObserver(UINT frame, UINT, DWORD eventaddress); \ No newline at end of file diff --git a/Src Backup/JassMachine.cpp b/Src Backup/JassMachine.cpp deleted file mode 100644 index 0b11610..0000000 --- a/Src Backup/JassMachine.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "JassMachine.h" - -#include "Variables.h" -#include "Mem.h" -#include "LuaMachine.h" - -DWORD OPCODES_FUNCTIONS[44]; - -DWORD _declspec(naked) jassOpcodeStartLuaThread() { - _asm { - push edi - push esi - call startLuaThread - - sub esp, 8 - mov[esp], eax - add esp, 8 - mov eax, gameBase - add eax, 0x45f79a - push eax - sub esp, 4 - pop eax - - ret - } -} -// game.dll + 45969d -void jassOpcodeInitialize() { - DWORD overflow = MakePtr(gameBase, _overflowOpcodeProc); - memcpy(OPCODES_FUNCTIONS, (LPVOID)MakePtr(gameBase, _opcodeList), sizeof(OPCODES_FUNCTIONS)); - OPCODES_FUNCTIONS[42] = overflow; - OPCODES_FUNCTIONS[43] = (DWORD)jassOpcodeStartLuaThread; // My own opcode function - - DWORD dwOldProtect; - DWORD address = MakePtr(gameBase, _opcodeListSize); - VirtualProtect((LPVOID)address, 1, PAGE_EXECUTE_READWRITE, &dwOldProtect); - *(BYTE*)address = sizeof(OPCODES_FUNCTIONS) / 4 - 1; - VirtualProtect((LPVOID)address, 1, dwOldProtect, &dwOldProtect); - - address = MakePtr(gameBase, _opcodeSwitch); - VirtualProtect((LPVOID)address, 4, PAGE_EXECUTE_READWRITE, &dwOldProtect); - *(DWORD*)address = (DWORD)OPCODES_FUNCTIONS; - VirtualProtect((LPVOID)address, 4, dwOldProtect, &dwOldProtect); -} \ No newline at end of file diff --git a/Src Backup/JassMachine.h b/Src Backup/JassMachine.h deleted file mode 100644 index 0d2a12b..0000000 --- a/Src Backup/JassMachine.h +++ /dev/null @@ -1,148 +0,0 @@ -#pragma once - -#include -#include - -#include "Warcraft.h" - -enum OPCODES { - OPTYPE_MINLIMIT = 0x00, - OPTYPE_ENDPROGRAM = 0x01, - OPTYPE_OLDJUMP = 0x02, - OPTYPE_FUNCTION = 0x03, - OPTYPE_ENDFUNCTION = 0x04, - OPTYPE_LOCAL = 0x05, - OPTYPE_GLOBAL = 0x06, - OPTYPE_CONSTANT = 0x07, - OPTYPE_FUNCARG = 0x08, - OPTYPE_EXTENDS = 0x09, - OPTYPE_TYPE = 0x0A, - OPTYPE_POPN = 0x0B, - OPTYPE_MOVRLITERAL = 0x0C, - OPTYPE_MOVRR = 0x0D, - OPTYPE_MOVRV = 0x0E, - OPTYPE_MOVRCODE = 0x0F, - OPTYPE_MOVRA = 0x10, - OPTYPE_MOVVR = 0x11, - OPTYPE_MOVAR = 0x12, - OPTYPE_PUSH = 0x13, - OPTYPE_POP = 0x14, - OPTYPE_CALLNATIVE = 0x15, - OPTYPE_CALLJASS = 0x16, - OPTYPE_I2R = 0x17, - OPTYPE_AND = 0x18, - OPTYPE_OR = 0x19, - OPTYPE_EQUAL = 0x1A, - OPTYPE_NOTEQUAL = 0x1B, - OPTYPE_LESSEREQUAL = 0x1C, - OPTYPE_GREATEREQUAL = 0x1D, - OPTYPE_LESSER = 0x1E, - OPTYPE_GREATER = 0x1F, - OPTYPE_ADD = 0x20, - OPTYPE_SUB = 0x21, - OPTYPE_MUL = 0x22, - OPTYPE_DIV = 0x23, - OPTYPE_MOD = 0x24, - OPTYPE_NEGATE = 0x25, - OPTYPE_NOT = 0x26, - OPTYPE_RETURN = 0x27, - OPTYPE_LABEL = 0x28, - OPTYPE_JUMPIFTRUE = 0x29, - OPTYPE_JUMPIFFALSE = 0x2A, - OPTYPE_JUMP = 0x2B, - OPTYPE_MAXLIMIT = 0x2C, - OPTYPE_STARTLUATHREAD = 0x2D -}; - -enum OPCODE_VARIABLE_TYPE { - OPCODE_VARIABLE_NOTHING = 0, - OPCODE_VARIABLE_UNKNOWN, - OPCODE_VARIABLE_NULL, - OPCODE_VARIABLE_CODE, - OPCODE_VARIABLE_INTEGER, - OPCODE_VARIABLE_REAL, - OPCODE_VARIABLE_STRING, - OPCODE_VARIABLE_HANDLE, - OPCODE_VARIABLE_BOOLEAN, - OPCODE_VARIABLE_INTEGER_ARRAY, - OPCODE_VARIABLE_REAL_ARRAY, - OPCODE_VARIABLE_STRING_ARRAY, - OPCODE_VARIABLE_HANDLE_ARRAY, - OPCODE_VARIABLE_BOOLEAN_ARRAY -}; - -#ifndef _JassMachine_h -#define _JassMachine_h -typedef struct { - DWORD unk; - DWORD zero1; - DWORD zero2; - DWORD zero3; - DWORD zero4; - DWORD zero5; - DWORD type1; - DWORD type2; - DWORD value; - DWORD zero6; - - void set(DWORD value, OPCODE_VARIABLE_TYPE type) { - this->value = value; - type1 = type; - type2 = type; - } - -} JASS_DATA_SLOT, * PJASS_DATA_SLOT; - -typedef struct { -private: - DWORD unk1; - DWORD unk2; - size_t stack_top; // Idk why it's here - PJASS_DATA_SLOT stack[32]; - size_t size; -public: - PJASS_DATA_SLOT pop() { - return stack[--size]; - } - - PJASS_DATA_SLOT& operator[](size_t index) { - return stack[index]; - } - - void clear(size_t number) { - size = number < size ? size - number : 0; - } - - size_t Size() { - return size; - } -} JASS_STACK, * PJASS_STACK; - -typedef struct { -private: - std::vector oplist; -public: - void addop(BYTE opcode, BYTE reg = 0, DWORD value = NULL, BYTE type = OPCODE_VARIABLE_NOTHING, BYTE rettype = OPCODE_VARIABLE_NOTHING) { - JASS_OPCODE* _opcode = new JASS_OPCODE; - _opcode->rettype = rettype; - _opcode->type = type; - _opcode->reg = reg; - _opcode->opcode = opcode; - _opcode->value = value; - - oplist.push_back(*_opcode); - } - - DWORD getcode() { - //return (DWORD)oplist.data(); - //printf("%08X\n", getJassMachine()); - - return ((DWORD)&oplist - (DWORD)getJassMachine()->code_table->codes) / 4; - } - -} JASS_OPLIST, * PJASS_OPLIST; -#endif - -//--------------------------------------------------------- - -void jassOpcodeInitialize(); \ No newline at end of file diff --git a/Src Backup/JassNatives.cpp b/Src Backup/JassNatives.cpp deleted file mode 100644 index 95aee39..0000000 --- a/Src Backup/JassNatives.cpp +++ /dev/null @@ -1,156 +0,0 @@ -#include "JassNatives.h" - -#include "Variables.h" -#include "Mem.h" -#include "JassMachine.h" - -std::map jassnatives; -std::map triggers; - -DWORD to_Code(lua_State* l, int index) { - DWORD key = (DWORD)lua_topointer(l, index); - - auto it = triggers.find(key); - - if (it != triggers.end()) { - return (DWORD)&it->second; - } - - JASS_OPLIST& oplist = triggers[key]; - - BYTE reg = 0xD8; - oplist.addop(OPTYPE_MOVRLITERAL, reg, pushFunctionRef(l, index), OPCODE_VARIABLE_INTEGER); - oplist.addop(OPTYPE_PUSH, reg); - oplist.addop(OPTYPE_MOVRLITERAL, reg, (DWORD)l, OPCODE_VARIABLE_INTEGER); - oplist.addop(OPTYPE_PUSH, reg); - oplist.addop(OPTYPE_STARTLUATHREAD); - oplist.addop(OPTYPE_MOVRR); - oplist.addop(OPTYPE_RETURN); - - return oplist.getcode(); -} - -//--------------------------------------------------------- - - -#pragma pack(push) -#pragma pack(1) -struct asm_opcode_5 { - BYTE opcode; - DWORD value; -}; -#pragma pack(pop) - -struct asm_register_native_function { -private: - asm_opcode_5 push; - asm_opcode_5 mov_edx; - asm_opcode_5 mov_ecx; - asm_opcode_5 call; -public: - bool verify() { - return ((push.opcode == 0x68) && (mov_edx.opcode == 0xBA) && (mov_ecx.opcode == 0xB9) && (call.opcode == 0xE8)); - } - - const char* get_params() { - return (const char*)(push.value); - } - - const char* get_name() { - return (const char*)(mov_edx.value); - } - - uintptr_t get_address() { - return (uintptr_t)(mov_ecx.value); - } -}; - -//--------------------------------------------------------- - -JASSNATIVE::JASSNATIVE(DWORD address, LPCSTR params) : _address(address) { - LPCSTR it = params++; - bool is_end = false; - - for (; *it; it++) { - if (*it == ')') { - is_end = true; - } - else if (isupper(*it)) { - if (is_end) { - _rettype = (JASS_TYPE)*it; - - break; - } - else { - _params.push_back((JASS_TYPE)*it); - } - } - } -} - -JASSNATIVE::JASSNATIVE() : _address(NULL), _rettype(TYPE_NONE) {} - -bool JASSNATIVE::is_valid() { - return _rettype != TYPE_NONE ? true : false; -} - -bool JASSNATIVE::is_sleep() { - return has_sleep; -} - -void JASSNATIVE::set_sleep(bool sleep) { - has_sleep = sleep; -} - -const std::vector& JASSNATIVE::get_params() { - return _params; -} - -const JASS_TYPE& JASSNATIVE::get_rettype() { - return _rettype; -} - -DWORD JASSNATIVE::get_address() { - return _address; -} - -DWORD JASSNATIVE::call(DWORD* params, int size) { - uintptr_t func_address = _address; - DWORD retval; - uintptr_t esp_ptr; - size_t params_size = size * sizeof DWORD; - - _asm { - sub esp, params_size - mov esp_ptr, esp - } - - memcpy((LPVOID)esp_ptr, params, params_size); - - _asm { - call[func_address] - mov esp, esp_ptr - add esp, params_size - mov retval, eax - } - - return retval; -} - -//--------------------------------------------------------- - -JASSNATIVE& get_native(LPCSTR lpName) { - for (auto& e : jassnatives) { - if (!strcmp(e.first, lpName)) { - return e.second; - } - } - - return *(JASSNATIVE*)NULL; -} - -void jassNativesInitialize() { - for (asm_register_native_function* ptr = (asm_register_native_function*)MakePtr(gameBase, _jassNativesList); ptr->verify(); ptr++) { - jassnatives[ptr->get_name()] = JASSNATIVE(ptr->get_address(), ptr->get_params()); - } -} \ No newline at end of file diff --git a/Src Backup/JassNatives.h b/Src Backup/JassNatives.h deleted file mode 100644 index 7d70df0..0000000 --- a/Src Backup/JassNatives.h +++ /dev/null @@ -1,189 +0,0 @@ -#pragma once - -#include -#include - -#include "LuaMachine.h" - -typedef void jNothing; -typedef UINT32 jBoolean; -typedef UINT32 jCode; -typedef UINT32 jHandle; -typedef INT32 jInteger; -typedef UINT32 jReal; -typedef UINT32 jString; -typedef UINT32 jTrigger; - -const jBoolean jTrue = 1; -const jBoolean jFalse = 0; -const jHandle jNull = 0; - -typedef DWORD HUNIT; -typedef DWORD HWIDGET; -typedef DWORD HLIGHTNING; -typedef DWORD HPLAYER; -typedef DWORD HEFFECT; -typedef DWORD HLOCATION; -typedef DWORD HEFFECTTYPE; -typedef DWORD HRECT; -typedef DWORD HWEATHEREFFECT; -typedef DWORD HCAMERAFIELD; -typedef DWORD HBOOLEXPR; -typedef DWORD HSOUND; -typedef DWORD HCAMERASETUP; -typedef DWORD HITEMTYPE; -typedef DWORD HCONDITIONFUNC; -typedef DWORD HAIDIFFICULTY; -typedef DWORD HALLIANCETYPE; -typedef DWORD HATTACKTYPE; -typedef DWORD HBLENDMODE; -typedef DWORD HDAMAGETYPE; -typedef DWORD HDIALOGEVENT; -typedef DWORD HFGAMESTATE; -typedef DWORD HFOGSTATE; -typedef DWORD HGAMEDIFFICULTY; -typedef DWORD HGAMEEVENT; -typedef DWORD HGAMESPEED; -typedef DWORD HGAMETYPE; -typedef DWORD HIGAMESTATE; -typedef DWORD HLIMITOP; -typedef DWORD HMAPCONTROL; -typedef DWORD HMAPDENSITY; -typedef DWORD HMAPFLAG; -typedef DWORD HMAPSETTING; -typedef DWORD HMAPVISIBILITY; -typedef DWORD HPATHINGTYPE; -typedef DWORD HPLACEMENT; -typedef DWORD HPLAYERCOLOR; -typedef DWORD HPLAYEREVENT; -typedef DWORD HPLAYERGAMERESULT; -typedef DWORD HPLAYERSCORE; -typedef DWORD HPLAYERSLOTSTATE; -typedef DWORD HPLAYERSTATE; -typedef DWORD HPLAYERUNITEVENT; -typedef DWORD HRACE; -typedef DWORD HRACEPREFERENCE; -typedef DWORD HRARITYCONTROL; -typedef DWORD HSOUNDTYPE; -typedef DWORD HSTARTLOCPRIO; -typedef DWORD HTEXMAPFLAGS; -typedef DWORD HUNITEVENT; -typedef DWORD HUNITSTATE; -typedef DWORD HUNITTYPE; -typedef DWORD HVERSION; -typedef DWORD HVOLUMEGROUP; -typedef DWORD HWEAPONTYPE; -typedef DWORD HWIDGETEVENT; -typedef DWORD HDESTRUCTABLE; -typedef DWORD HDEFEATCONDITION; -typedef DWORD HFOGMODIFIER; -typedef DWORD HFORCE; -typedef DWORD HGROUP; -typedef DWORD HIMAGE; -typedef DWORD HITEM; -typedef DWORD HITEMPOOL; -typedef DWORD HLEADERBOARD; -typedef DWORD HMULTIBOARD; -typedef DWORD HQUEST; -typedef DWORD HREGION; -typedef DWORD HTEXTTAG; -typedef DWORD HTIMER; -typedef DWORD HTIMERDIALOG; -typedef DWORD HTRACKABLE; -typedef DWORD HUBERSPLAT; -typedef DWORD HUNITPOOL; -typedef DWORD HFILTERFUNC; -typedef DWORD HDIALOG; -typedef DWORD HBUTTON; -typedef DWORD HHASHTABLE; -typedef DWORD HGAMECACHE; -typedef DWORD HGAMESTATE; -typedef DWORD HHANDLE; -typedef DWORD HABILITY; -typedef DWORD HEVENTID; -typedef DWORD HQUESTITEM; -typedef DWORD HMULTIBOARDITEM; -typedef DWORD HTRIGGERACTION; -typedef DWORD HTRIGGERCONDITION; -typedef DWORD HEVENT; -typedef DWORD HAGENT; -typedef DWORD HTERRAINDEFORMATION; - -enum JASS_TYPE { - TYPE_NONE = 0, - TYPE_BOOLEAN = 'B', - TYPE_CODE = 'C', - TYPE_HANDLE = 'H', - TYPE_INTEGER = 'I', - TYPE_REAL = 'R', - TYPE_STRING = 'S', - TYPE_NOTHING = 'V', -}; - -inline jReal to_jReal(float fX) { - return *(jReal*)&fX; -} - -inline float from_jReal(jReal val) { - return *(float*)&val; -} - -inline jString to_jString(LPCSTR lpString) { - UINT32* string = new UINT32[8]; - - string[2] = (UINT32)&string[0]; - string[7] = (UINT32)&lpString[0]; - - return (jString)string; -} - -inline LPCSTR from_jString(jString string) { - if (!string) { - return NULL; - } - - string = ((jString*)string)[2]; - - if (!string) { - return NULL; - } - - return (LPCSTR)((jString*)string)[7]; -} - -DWORD to_Code(lua_State* l, int index); - -inline jInteger to_ID(LPCSTR lpID) { - return (lpID[0] << 24) + (lpID[1] << 16) + (lpID[2] << 8) + lpID[3]; -} - -//--------------------------------------------------------- - -#ifndef _JassNatives_h -#define _JassNatives_h -class JASSNATIVE { -public: - JASSNATIVE(DWORD address, LPCSTR params); - JASSNATIVE(); - - bool is_valid(); - bool is_sleep(); - void set_sleep(bool sleep); - const std::vector& get_params(); - const JASS_TYPE& get_rettype(); - DWORD get_address(); - - DWORD call(DWORD* params, int size); -private: - DWORD _address; - std::vector _params; - JASS_TYPE _rettype; - bool has_sleep = false; -}; -#endif - -//--------------------------------------------------------- - -JASSNATIVE& get_native(LPCSTR lpName); - -void jassNativesInitialize(); \ No newline at end of file diff --git a/Src Backup/LuaMachine.cpp b/Src Backup/LuaMachine.cpp deleted file mode 100644 index bccce79..0000000 --- a/Src Backup/LuaMachine.cpp +++ /dev/null @@ -1,438 +0,0 @@ -#include "LuaMachine.h" - -#include -#include -#pragma comment(lib, "storm.lib") - -#include "Variables.h" -#include "LuaRegister.h" -#include "Warcraft.h" -#include "Mem.h" - -lua_State* mainLuaState = NULL; -bool running = false; - - -//--------------------------------------------------------------------------------- -// Utils - -BOOL isInGameCatalog(LPCSTR fileName) { - char filepath[MAX_PATH] = { 0 }; - GetFullPathName(fileName, sizeof(filepath), filepath, NULL); - - char path[MAX_PATH] = { 0 }; - GetModuleFileName(GetModuleHandle(NULL), path, sizeof(path)); - for (int i = strlen(path); path[i] != '\\'; path[i] = NULL, i--); - - return !_strnicmp(filepath, path, strlen(path)) ? TRUE : FALSE; -} - -BOOL isAllowedExtension(LPCSTR fileName) { - char* fileextension = (char*)fileName + strlen(fileName); - - for (; fileextension[0] != '.'; fileextension--); - fileextension++; - - std::vector extensions = { "exe", "dll", "asi", "mix", "m3d", "mpq", "w3x", "w3m", "w3n" }; - for (const auto& extension : extensions) { - if (!_strnicmp(fileextension, extension, strlen(extension))) { - return FALSE; - } - } - - return TRUE; -} - -//--------------------------------------------------------------------------------- -// File stream only in catalog - -// Open -luaL_Stream* newprefile(lua_State* L) { - luaL_Stream* p = (luaL_Stream*)lua_newuserdatauv(L, sizeof(luaL_Stream), 0); - p->closef = NULL; - luaL_setmetatable(L, LUA_FILEHANDLE); - return p; -} - -int io_fclose(lua_State* L) { - luaL_Stream* p = (luaL_Stream*)luaL_checkudata(L, 1, LUA_FILEHANDLE); - int res = fclose(p->f); - return luaL_fileresult(L, (res == 0), NULL); -} - -luaL_Stream* newfile(lua_State* L) { - luaL_Stream* p = newprefile(L); - p->f = NULL; - p->closef = &io_fclose; - return p; -} - -int l_checkmode(const char* mode) { - return (*mode != '\0' && strchr("rwa", *(mode++)) != NULL && (*mode != '+' || ((void)(++mode), 1)) && (strspn(mode, "b") == strlen(mode))); -} - -int io_open(lua_State* L) { - const char* filename = luaL_checkstring(L, 1); - const char* mode = luaL_optstring(L, 2, "r"); - - if (!isInGameCatalog(filename) || !isAllowedExtension(filename)) { - return luaL_fileresult(L, FALSE, filename); - } - - luaL_Stream* p = newfile(L); - const char* md = mode; - luaL_argcheck(L, l_checkmode(md), 2, "invalid mode"); - fopen_s(&(p->f), filename, mode); - return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; -} - -// Remove -int os_remove(lua_State* L) { - const char* filename = luaL_checkstring(L, 1); - - if (!isInGameCatalog(filename) || !isAllowedExtension(filename)) { - return luaL_fileresult(L, FALSE, filename); - } - - return luaL_fileresult(L, remove(filename) == 0, filename); -} - -// Rename -int os_rename(lua_State* L) { - const char* fromname = luaL_checkstring(L, 1); - const char* toname = luaL_checkstring(L, 2); - - if (!isInGameCatalog(fromname) || !isAllowedExtension(fromname) || !isInGameCatalog(toname) || !isAllowedExtension(toname)) { - return luaL_fileresult(L, FALSE, NULL); - } - - return luaL_fileresult(L, rename(fromname, toname) == 0, NULL); -} - -void lua_replaceFileStreamFunctions(lua_State* l) { - lua_getglobal(l, "io"); - lua_pushcfunction(l, io_open); - lua_setfield(l, -2, "open"); - - lua_pop(l, 1); - - lua_getglobal(l, "os"); - lua_pushcfunction(l, os_remove); - lua_setfield(l, -2, "remove"); - - lua_pushcfunction(l, os_rename); - lua_setfield(l, -2, "rename"); - - lua_pop(l, 1); -} - -//--------------------------------------------------------------------------------- -// Disabled functions - -void disable_functions(lua_State* l) { - lua_getglobal(l, "os"); - - std::vector functions = { "execute", "getenv", "setlocale", "tmpname" }; - - for (const auto& function : functions) { - lua_pushnil(l); - lua_setfield(l, -2, function); - } - - lua_pop(l, 1); - - lua_getglobal(l, "io"); - - functions = { "stdin", "stdout", "stderr", "flush", "input", "lines", "output", "popen", "tmpfile", "type" }; - - for (const auto& function : functions) { - lua_pushnil(l); - lua_setfield(l, -2, function); - } - - lua_pop(l, 1); - - lua_pushnil(l); - lua_setglobal(l, "dofile"); - -} - -//--------------------------------------------------------------------------------- -// Loader lua from mpq - - -// Lua -int checkload(lua_State* L, int stat, const char* filename) { - if (stat) { - lua_pushstring(L, filename); - return 2; - } - else { - return luaL_error(L, "error loading module '%s' from file '%s':\n\t%s", lua_tostring(L, 1), filename, lua_tostring(L, -1)); - } -} - -int searcher_Lua(lua_State* l) { - HANDLE map = *(HANDLE*)MakePtr(gameBase, _mapMPQ); - - std::string scriptName = luaL_checkstring(l, 1) + std::string(".lua"); - lua_pop(l, 1); - - char mapName[MAX_PATH] = { 0 }; - SFileGetArchiveName(map, mapName, sizeof(mapName)); - std::string scriptPath = mapName; - - for (size_t i = scriptPath.size(); i > 0; i--) { - if (scriptPath[i] == '\\') { - scriptPath = scriptPath.substr(i + 1); - - break; - } - } - - scriptPath = "(" + scriptPath + "):\\" + scriptName; - - HANDLE script; - if (SFileOpenFileEx(map, scriptName.c_str(), NULL, &script)) { - int lenght = SFileGetFileSize(script, NULL); - char* buffer = new char[lenght + 1]; - - ZeroMemory(buffer, lenght + 1); - - SFileReadFile(script, buffer, lenght, NULL, NULL); - SFileCloseFile(script); - - int result = checkload(l, (luaL_loadbuffer(l, buffer, strlen(buffer), ("@" + scriptPath).c_str()) == LUA_OK), scriptName.c_str()); - delete[] buffer; - - return result; - } - - lua_pushstring(l, std::string("no file '" + scriptPath + "'").c_str()); - - return 1; -} - -void lua_replaceSearchers(lua_State* l) { - std::vector searchers; - - lua_getglobal(l, "package"); - lua_getfield(l, -1, "searchers"); - - lua_rawgeti(l, -1, 1); - searchers.push_back(lua_tocfunction(l, -1)); - lua_pop(l, 2); - - searchers.push_back(searcher_Lua); - - lua_newtable(l); - - for (size_t i = 0; i < searchers.size(); i++) { - lua_pushvalue(l, -2); - lua_pushcclosure(l, searchers[i], 1); - lua_rawseti(l, -2, i + 1); - } - - lua_setfield(l, -2, "searchers"); - - lua_pop(l, 1); - searchers.clear(); -} - -//--------------------------------------------------------------------------------- - -lua_State* getMainLuaState() { - if (!mainLuaState) { - lua_State* l = mainLuaState = luaL_newstate(); - - luaL_openlibs(l); - disable_functions(l); - lua_open_jassnatives(l); - lua_open_warcraftfunctions(l); - lua_replaceSearchers(l); - lua_replaceFileStreamFunctions(l); - } - - return mainLuaState; -} - -lua_State* createThread(lua_State* l, int index) { - lua_pushvalue(l, index); - getGlobalTable(l, "_LUA_THREADS", false); - lua_pushvalue(l, -2); - - if (lua_rawget(l, -2) != LUA_TTHREAD) { - lua_pop(l, 1); - lua_newthread(l); - lua_pushvalue(l, -3); - lua_pushvalue(l, -2); - lua_rawset(l, -4); - } - - lua_State* thread = lua_tothread(l, -1); - lua_pop(l, 3); - - return thread; -} - -void clearScreen() { - HANDLE hStdOut; - CONSOLE_SCREEN_BUFFER_INFO csbi; - DWORD count; - DWORD cellCount; - COORD homeCoords = { 0, 0 }; - - hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); - - if (hStdOut == INVALID_HANDLE_VALUE) { - return; - } - - if (!GetConsoleScreenBufferInfo(hStdOut, &csbi)) { - return; - } - - cellCount = csbi.dwSize.X * csbi.dwSize.Y; - - if (!FillConsoleOutputCharacter(hStdOut, ' ', cellCount, homeCoords, &count)) { - return; - } - - if (!FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, cellCount, homeCoords, &count)) { - return; - } - - SetConsoleCursorPosition(hStdOut, homeCoords); -} - -void destroyMainLuaState() -{ - if (mainLuaState) { - lua_close(mainLuaState); - mainLuaState = NULL; - running = false; - triggers.clear(); - frameEventHashTable.clear(); - } - - clearScreen(); -} - -lua_State* getMainThread(lua_State* thread) { - lua_rawgeti(thread, LUA_REGISTRYINDEX, LUA_RIDX_MAINTHREAD); - lua_State* l = lua_tothread(thread, -1); - lua_pop(thread, 1); - - return l; -} - -BOOL getGlobalTable(lua_State* l, LPCSTR name, bool weak) { - lua_getfield(l, LUA_REGISTRYINDEX, name); - - if (!lua_istable(l, -1)) { - lua_pop(l, 1); - lua_newtable(l); - - if (weak) { - lua_newtable(l); - lua_pushstring(l, "__mode"); - lua_pushstring(l, "kv"); - lua_rawset(l, -3); - - lua_setmetatable(l, -2); - } - - lua_pushvalue(l, -1); - lua_setfield(l, LUA_REGISTRYINDEX, name); - - return FALSE; - } - - return TRUE; -} - -int pushFunctionRef(lua_State* l, int index) { - lua_pushvalue(l, index); - getGlobalTable(l, "_LUA_FUNCTIONS_REF", false); - - int ref = (int)lua_rawlen(l, -1); - lua_pushvalue(l, -2); - lua_rawseti(l, -2, ++ref); - - lua_pop(l, 2); - - return ref; -} - -void getFunctionByRef(lua_State* l, int ref) { - getGlobalTable(l, "_LUA_FUNCTIONS_REF", false); - lua_rawgeti(l, -1, ref); - lua_remove(l, -2); -} - -void lua_throwerr(lua_State* l) { - running = false; - - LPCSTR error = lua_tostring(l, -1); - printf("--------------------Lua Error--------------------\n%s\n-------------------------------------------------\n\n", error); - MessageBox(FindWindow("Warcraft III", NULL), error, "Lua Error", MB_ICONHAND | MB_TOPMOST ); -} - -LUA stacktrace(lua_State* L) -{ - luaL_traceback(L, L, lua_tostring(L, -1), 0); - - return 1; -} - -DWORD startLua() { - destroyMainLuaState(); - - lua_State* l = getMainLuaState(); - - HANDLE war3luaScript; - - if (SFileOpenFileEx(*(HANDLE*)MakePtr(gameBase, _mapMPQ), "war3map.lua", NULL, &war3luaScript)) { - SFileCloseFile(war3luaScript); - - running = true; - - lua_pushcfunction(l, stacktrace); - lua_getglobal(l, "require"); - lua_pushstring(l, "war3map"); - if (lua_pcall(l, 1, LUA_MULTRET, -3) != LUA_OK) { - lua_throwerr(l); - } - - lua_pop(l, 1); - } - - return 0; -} - -BOOL __stdcall startLuaThread(DWORD esi, DWORD edi) { - if (!running) { - return FALSE; - } - - PJASS_STACK stack = (PJASS_STACK) * (DWORD*)(esi + 0x2868); - - lua_State* l = (lua_State*)stack->pop()->value; - getFunctionByRef(l, stack->pop()->value); - lua_State* thread = createThread(l, -1); - lua_xmove(l, thread, 1); - - int res; - switch (lua_resume(thread, l, 0, &res)) { - case LUA_OK: - ((PJASS_DATA_SLOT)(esi + 80))->set(lua_toboolean(thread, 1), OPCODE_VARIABLE_BOOLEAN); - - break; - case LUA_ERRRUN: - lua_throwerr(thread); - - break; - } - - return TRUE; -} \ No newline at end of file diff --git a/Src Backup/LuaMachine.h b/Src Backup/LuaMachine.h deleted file mode 100644 index 30eea9d..0000000 --- a/Src Backup/LuaMachine.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include - -#include -#pragma comment(lib, "lua.lib") - -typedef int LUA; - -lua_State* getMainLuaState(); - -void destroyMainLuaState(); - -lua_State* getMainThread(lua_State* thread); - -lua_State* createThread(lua_State* l, int index); - -void lua_throwerr(lua_State* l); - -BOOL getGlobalTable(lua_State* l, LPCSTR name, bool weak); - -int pushFunctionRef(lua_State* l, int index); - -void getFunctionByRef(lua_State* l, int ref); - -DWORD startLua(); - -BOOL CALLBACK startLuaThread(DWORD esi, DWORD edi); \ No newline at end of file diff --git a/Src Backup/LuaRegister.cpp b/Src Backup/LuaRegister.cpp deleted file mode 100644 index 328f332..0000000 --- a/Src Backup/LuaRegister.cpp +++ /dev/null @@ -1,405 +0,0 @@ -#include "LuaRegister.h" - -#include "WarcraftFunctions.h" -#include "Variables.h" -#include "Warcraft.h" -#include "JassNatives.h" -#include "FrameAPI.h" - -#define lua_registerJassNative(L, n, f) (lua_pushstring(L, (n)), lua_pushcclosure(L, (f), 1), lua_setglobal(L, (n))) -#define lua_setint(L, n, v) (lua_pushinteger(L, v), lua_setglobal(L, n)) - -LUA lua_jCall(lua_State* l) { - LPCSTR name = lua_tostring(l, lua_upvalueindex(1)); - JASSNATIVE native = get_native(name); - - if (!native.is_valid()) { - return 0; - } - - { - std::vector params = native.get_params(); - int size = params.size(); - if (size > lua_gettop(l)) { - return luaL_error(l, "function '%s' must have %d %s", name, size, size > 1 ? "arguments" : "argument"); - } - } - - int size = lua_gettop(l); - float* temp_params = new float[size]; - DWORD* params = new DWORD[size]; - ZeroMemory(temp_params, size); - ZeroMemory(params, size); - UINT i = 1; - - for (const auto& type : native.get_params()) { - switch (type) { - case TYPE_CODE: - if (lua_isinteger(l, i)) { - params[i - 1] = (DWORD)lua_tointeger(l, i); - } - else if (lua_isfunction(l, i)) { - params[i - 1] = to_Code(l, i); - } - - break; - case TYPE_BOOLEAN: - params[i - 1] = (DWORD)lua_toboolean(l, i); - - break; - case TYPE_HANDLE: - params[i - 1] = (DWORD)lua_tointeger(l, i); - - break; - case TYPE_INTEGER: - if (lua_isinteger(l, i)) { - params[i - 1] = (DWORD)lua_tointeger(l, i); - } - else { - params[i - 1] = to_ID(lua_tostring(l, i)); - } - - break; - case TYPE_REAL: { - temp_params[i - 1] = (float)lua_tonumber(l, i); - params[i - 1] = (DWORD)&(temp_params[i - 1]); - - break; - } - case TYPE_STRING: - params[i - 1] = to_jString(lua_tostring(l, i)); - - break; - default: - params[i - 1] = NULL; - - break; - } - - i++; - } - - DWORD result = native.call(params, size); - delete[] temp_params; - delete[] params; - - switch (native.get_rettype()) { - case TYPE_BOOLEAN: - lua_pushboolean(l, result); - - break; - - case TYPE_CODE: - case TYPE_HANDLE: - case TYPE_INTEGER: - lua_pushinteger(l, result); - - break; - case TYPE_REAL: - lua_pushnumber(l, from_jReal(result)); - - break; - case TYPE_STRING: - lua_pushstring(l, from_jString(getJassMachine()->string_table->get(result))); - - break; - } - - return native.get_rettype() != TYPE_NOTHING ? 1 : 0; -} - -//------------------------------------------------------------- - -LUA lua_GetMouseWorldPos(lua_State* l) { - PVECTOR3 mousePos = GetMouseWorldPos(); - - lua_pushnumber(l, mousePos->_x); - lua_pushnumber(l, mousePos->_y); - lua_pushnumber(l, mousePos->_z); - - return 3; -} - -LUA lua_GetMouseWorldX(lua_State* l) { - lua_pushnumber(l, GetMouseWorldX()); - - return 1; -} - -LUA lua_GetMouseWorldY(lua_State* l) { - lua_pushnumber(l, GetMouseWorldY()); - - return 1; -} - -LUA lua_GetMouseWorldZ(lua_State* l) { - lua_pushnumber(l, GetMouseWorldZ()); - - return 1; -} - -LUA lua_GetObjectPos(lua_State* l) { - PVECTOR3 objectPos = GetObjectPos(ConvertHandleToObject((UINT)lua_tointeger(l, 1))); - - lua_pushnumber(l, objectPos->_x); - lua_pushnumber(l, objectPos->_y); - lua_pushnumber(l, objectPos->_z); - - return 3; -} - -LUA lua_GetObjectX(lua_State* l) { - lua_pushnumber(l, GetObjectPos(ConvertHandleToObject((UINT)lua_tointeger(l, 1)))->_x); - - return 1; -} - -LUA lua_GetObjectY(lua_State* l) { - lua_pushnumber(l, GetObjectPos(ConvertHandleToObject((UINT)lua_tointeger(l, 1)))->_y); - - return 1; -} - -LUA lua_GetObjectZ(lua_State* l) { - lua_pushnumber(l, GetObjectPos(ConvertHandleToObject((UINT)lua_tointeger(l, 1)))->_z); - - return 1; -} - -LUA lua_SetObjectPos(lua_State* l) { - UINT_PTR object = ConvertHandleToObject((UINT)lua_tointeger(l, 1)); - - switch (lua_gettop(l)) - { - case 2: - SetObjectX(object, (float)lua_tonumber(l, 2)); - - break; - case 3: - SetObjectX(object, (float)lua_tonumber(l, 2)); - SetObjectY(object, (float)lua_tonumber(l, 3)); - - break; - case 4: - SetObjectPos(object, VECTOR3((float)lua_tonumber(l, 2), (float)lua_tonumber(l, 3), (float)lua_tonumber(l, 4))); - - break; - } - - return 0; -} - -LUA lua_SetObjectX(lua_State* l) { - SetObjectX(ConvertHandleToObject((UINT)lua_tointeger(l, 1)), (float)lua_tonumber(l, 2)); - - return 0; -} - -LUA lua_SetObjectY(lua_State* l) { - SetObjectY(ConvertHandleToObject((UINT)lua_tointeger(l, 1)), (float)lua_tonumber(l, 2)); - - return 0; -} - -LUA lua_SetObjectZ(lua_State* l) { - SetObjectZ(ConvertHandleToObject((UINT)lua_tointeger(l, 1)), (float)lua_tonumber(l, 2)); - - return 0; -} - -LUA lua_ConvertHandleToObject(lua_State* l) { - lua_pushinteger(l, ConvertHandleToObject((UINT)lua_tointeger(l, 1))); - - return 1; -} - -//------------------------------------------------------------- - -LUA lua_GetOriginFrame(lua_State* l) { - lua_pushinteger(l, GetOriginFrame((EOriginFrame)lua_tointeger(l, 1), (UINT)lua_tointeger(l, 2))); - - return 1; -} - -LUA lua_LoadTOCFile(lua_State* l) { - lua_pushinteger(l, LoadTOCFile(lua_tostring(l, 1))); - - return 1; -} - -LUA lua_GetFrameByName(lua_State* l) { - lua_pushinteger(l, GetFrameByName(lua_tostring(l, 1), (UINT)lua_tointeger(l, 2))); - - return 1; -} - -LUA lua_TriggerRegisterFrameEvent(lua_State* l) { - TriggerRegisterFrameEvent(pushFunctionRef(l, 1), (UINT)lua_tointeger(l, 2), (EFrameEvent)lua_tointeger(l, 3)); - - return 0; -} - -LUA lua_CreateFrame(lua_State* l) { - getGlobalTable(l, "_LUA_FRAMES", false); - lua_pushinteger(l, CreateFrame(lua_tostring(l, 1), (UINT)lua_tointeger(l, 2), (EFramePoint)lua_tointeger(l, 3), (EFramePoint)lua_tointeger(l, 4), (UINT)lua_tointeger(l, 5))); - - return 1; -} - -LUA lua_SetFrameText(lua_State* l) { - SetFrameText((UINT)lua_tointeger(l, 1), lua_tostring(l, 2)); - - return 0; -} - -LUA lua_SetFrameTextColor(lua_State* l) { - SetFrameTextColor((UINT)lua_tointeger(l, 1), (BYTE)lua_tointeger(l, 2), (BYTE)lua_tointeger(l, 3), (BYTE)lua_tointeger(l, 4), (BYTE)lua_tointeger(l, 5)); - - return 0; -} - -LUA lua_GetFrameTextHeight(lua_State* l) { - lua_pushnumber(l, GetFrameTextHeight((UINT)lua_tointeger(l, 1))); - - return 1; -} - -LUA lua_SetFrameWidth(lua_State* l) { - SetFrameWidth((UINT)lua_tointeger(l, 1), (float)lua_tonumber(l, 2)); - - return 0; -} - -LUA lua_SetFrameHeight(lua_State* l) { - SetFrameHeight((UINT)lua_tointeger(l, 1), (float)lua_tonumber(l, 2)); - - return 0; -} - -LUA lua_SetFrameSize(lua_State* l) { - SetFrameSize((UINT)lua_tointeger(l, 1), (float)lua_tonumber(l, 2), (float)lua_tonumber(l, 3)); - - return 0; -} - -LUA lua_SetFrameScale(lua_State* l) { - SetFrameScale((UINT)lua_tointeger(l, 1), (float)lua_tonumber(l, 2)); - - return 0; -} - -LUA lua_SetFrameAbsolutePoint(lua_State* l) { - SetFrameAbsolutePoint((UINT)lua_tointeger(l, 1), (EFramePoint)lua_tointeger(l, 2), (float)lua_tonumber(l, 3), (float)lua_tonumber(l, 4)); - - return 0; -} - -LUA lua_SetFramePoint(lua_State* l) { - SetFramePoint((UINT)lua_tointeger(l, 1), (EFramePoint)lua_tointeger(l, 2), (UINT)lua_tointeger(l, 3), (EFramePoint)lua_tointeger(l, 4), (float)lua_tonumber(l, 5), (float)lua_tonumber(l, 6)); - - return 0; -} - -LUA lua_GetFrameWidth(lua_State* l) { - lua_pushnumber(l, GetFrameWidth((UINT)lua_tointeger(l, 1))); - - return 1; -} - -LUA lua_GetFrameHeight(lua_State* l) { - lua_pushnumber(l, GetFrameHeight((UINT)lua_tointeger(l, 1))); - - return 1; -} - -LUA lua_GetFramePointParent(lua_State* l) { - lua_pushinteger(l, GetFramePointParent((UINT)lua_tointeger(l, 1), (EFramePoint)lua_tointeger(l, 2))); - - return 1; -} - -LUA lua_GetFramePointRelativePoint(lua_State* l) { - lua_pushinteger(l, GetFramePointRelativePoint((UINT)lua_tointeger(l, 1), (EFramePoint)lua_tointeger(l, 2))); - - return 1; -} - -LUA lua_GetFramePointX(lua_State* l) { - lua_pushnumber(l, GetFramePointX((UINT)lua_tointeger(l, 1), (EFramePoint)lua_tointeger(l, 2))); - - return 1; -} - -LUA lua_GetFramePointY(lua_State* l) { - lua_pushnumber(l, GetFramePointY((UINT)lua_tointeger(l, 1), (EFramePoint)lua_tointeger(l, 2))); - - return 1; -} - -//------------------------------------------------------------- - -void lua_open_jassnatives(lua_State* l) { - for (const auto& native : jassnatives) { - lua_registerJassNative(l, native.first, lua_jCall); - } -} - -void lua_open_warcraftfunctions(lua_State* l) { - lua_register(l, "TriggerRegisterFrameEvent", lua_TriggerRegisterFrameEvent); - - lua_register(l, "GetMouseWorldPos", lua_GetMouseWorldPos); - lua_register(l, "GetMouseWorldX", lua_GetMouseWorldX); - lua_register(l, "GetMouseWorldY", lua_GetMouseWorldY); - lua_register(l, "GetMouseWorldZ", lua_GetMouseWorldZ); - - lua_register(l, "GetObjectPos", lua_GetObjectPos); - lua_register(l, "GetObjectX", lua_GetObjectX); - lua_register(l, "GetObjectY", lua_GetObjectY); - lua_register(l, "GetObjectZ", lua_GetObjectZ); - - lua_register(l, "SetObjectPos", lua_SetObjectPos); - lua_register(l, "SetObjectX", lua_SetObjectX); - lua_register(l, "SetObjectY", lua_SetObjectY); - lua_register(l, "SetObjectZ", lua_SetObjectZ); - - lua_register(l, "ConvertHandleToObject", lua_ConvertHandleToObject); - - lua_setint(l, "ORIGIN_FRAME_GAME_UI", ORIGIN_FRAME_GAME_UI); - lua_setint(l, "ORIGIN_FRAME_WORLD_FRAME", ORIGIN_FRAME_WORLD_FRAME); - lua_setint(l, "ORIGIN_FRAME_HERO_BAR", ORIGIN_FRAME_HERO_BAR); - lua_setint(l, "ORIGIN_FRAME_HERO_BUTTON", ORIGIN_FRAME_HERO_BUTTON); - lua_setint(l, "ORIGIN_FRAME_HERO_HP_BAR", ORIGIN_FRAME_HERO_HP_BAR); - lua_setint(l, "ORIGIN_FRAME_HERO_MANA_BAR", ORIGIN_FRAME_HERO_MANA_BAR); - lua_setint(l, "ORIGIN_FRAME_HERO_BUTTON_INDICATOR", ORIGIN_FRAME_HERO_BUTTON_INDICATOR); - lua_setint(l, "ORIGIN_FRAME_ITEM_BUTTON", ORIGIN_FRAME_ITEM_BUTTON); - lua_setint(l, "ORIGIN_FRAME_COMMAND_BUTTON", ORIGIN_FRAME_COMMAND_BUTTON); - lua_setint(l, "ORIGIN_FRAME_SYSTEM_BUTTON", ORIGIN_FRAME_SYSTEM_BUTTON); - lua_setint(l, "ORIGIN_FRAME_PORTRAIT", ORIGIN_FRAME_PORTRAIT); - lua_setint(l, "ORIGIN_FRAME_MINIMAP", ORIGIN_FRAME_MINIMAP); - lua_setint(l, "ORIGIN_FRAME_MINIMAP_BUTTON", ORIGIN_FRAME_MINIMAP_BUTTON); - lua_setint(l, "ORIGIN_FRAME_TOOLTIP", ORIGIN_FRAME_TOOLTIP); - lua_setint(l, "ORIGIN_FRAME_UBERTOOLTIP", ORIGIN_FRAME_UBERTOOLTIP); - lua_setint(l, "ORIGIN_FRAME_CHAT_MSG", ORIGIN_FRAME_CHAT_MSG); - lua_setint(l, "ORIGIN_FRAME_UNIT_MSG", ORIGIN_FRAME_UNIT_MSG); - lua_setint(l, "ORIGIN_FRAME_TOP_MSG", ORIGIN_FRAME_TOP_MSG); - - lua_register(l, "GetOriginFrame", lua_GetOriginFrame); - lua_register(l, "LoadTOCFile", lua_LoadTOCFile); - lua_register(l, "GetFrameByName", lua_GetFrameByName); - lua_register(l, "CreateFrame", lua_CreateFrame); - lua_register(l, "SetFrameText", lua_SetFrameText); - lua_register(l, "SetFrameTextColor", lua_SetFrameTextColor); - lua_register(l, "GetFrameTextHeight", lua_GetFrameTextHeight); - lua_register(l, "SetFrameWidth", lua_SetFrameWidth); - lua_register(l, "SetFrameHeight", lua_SetFrameHeight); - lua_register(l, "SetFrameSize", lua_SetFrameSize); - lua_register(l, "SetFrameScale", lua_SetFrameScale); - lua_register(l, "SetFrameAbsolutePoint", lua_SetFrameAbsolutePoint); - lua_register(l, "SetFramePoint", lua_SetFramePoint); - lua_register(l, "GetFrameWidth", lua_GetFrameWidth); - lua_register(l, "GetFrameHeight", lua_GetFrameHeight); - lua_register(l, "GetFramePointParent", lua_GetFramePointParent); - lua_register(l, "GetFramePointRelativePoint", lua_GetFramePointRelativePoint); - lua_register(l, "GetFramePointX", lua_GetFramePointX); - lua_register(l, "GetFramePointY", lua_GetFramePointY); -} \ No newline at end of file diff --git a/Src Backup/LuaRegister.h b/Src Backup/LuaRegister.h deleted file mode 100644 index 9d3905b..0000000 --- a/Src Backup/LuaRegister.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include - -#include "LuaMachine.h" - -void lua_open_jassnatives(lua_State* l); -void lua_open_warcraftfunctions(lua_State* l); \ No newline at end of file diff --git a/Src Backup/Main.cpp b/Src Backup/Main.cpp deleted file mode 100644 index 6ca76a4..0000000 --- a/Src Backup/Main.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include - -#include "Variables.h" -#include "Mem.h" -#include "Hooks.h" -#include "JassMachine.h" - -BOOL APIENTRY DllMain(HMODULE hModule, UINT ul_reason_for_call, LPVOID lpReserve) -{ - switch (ul_reason_for_call) - { - case DLL_PROCESS_ATTACH: - if (gameBase) { - DisableThreadLibraryCalls(hModule); - - LPSTR cmdline = GetCommandLine(); - size_t i; - for (i = strlen(cmdline); i > 0 && cmdline[i] != '\"'; i--); - - if (strstr(&cmdline[i + 1], "-console") || strstr(&cmdline[i + 1], "-debug")) { - FILE* console; - AllocConsole(); - freopen_s(&console, "CONOUT$", "w", stdout); - SetConsoleTitle("Lua Console"); - } - - printf("%s\n%s\n", LUA_COPYRIGHT, WAR3_LUA); - - jassNativesInitialize(); - jassOpcodeInitialize(); - - call(MakePtr(gameBase, _jassEntryPoint), jassEntryPoint); - call(MakePtr(gameBase, _getWarcraftID1), getWarcraftID); - call(MakePtr(gameBase, _getWarcraftID2), getWarcraftID); - jmp(MakePtr(gameBase, 0x62a580), (DWORD)isFrameValid); - jmp(MakePtr(gameBase, 0x629a90), (DWORD)frameEventObserver); - - break; - } - else { - return FALSE; - } - case DLL_PROCESS_DETACH: - BYTE originalFrameValid[] = { 0x8b, 0x49, 8, 0x33, 0xc0}; - patch(MakePtr(gameBase, 0x62a580), originalFrameValid,sizeof(originalFrameValid)); - - BYTE originalFrameEventObserver[] = { 0x8b, 0x44, 0x24, 4, 0x8b }; - patch(MakePtr(gameBase, 0x629a90), originalFrameEventObserver, sizeof(originalFrameEventObserver)); - - break; - } - - return TRUE; -} \ No newline at end of file diff --git a/Src Backup/Mem.h b/Src Backup/Mem.h deleted file mode 100644 index e1a5e6a..0000000 --- a/Src Backup/Mem.h +++ /dev/null @@ -1,61 +0,0 @@ -#pragma once - -#include - -#define MakePtr(a, b) ((DWORD)a + (DWORD)b) - -inline bool patch(LPVOID lpAddress, LPVOID lpData, SIZE_T dwSize) { - DWORD dwOldProtect; - - if (VirtualProtect(lpAddress, dwSize, PAGE_EXECUTE_READWRITE, &dwOldProtect)) { - memcpy(lpAddress, lpData, dwSize); - - VirtualProtect(lpAddress, dwSize, dwOldProtect, NULL); - - return true; - } - - return false; -} - -inline bool patch(DWORD dwAddress, LPVOID lpData, SIZE_T dwSize) { - return patch((LPVOID)dwAddress, lpData, dwSize); -} - -inline bool call(LPVOID lpAddress, LPVOID lpProc) { - DWORD dwOldProtect; - - if (VirtualProtect(lpAddress, 5, PAGE_EXECUTE_READWRITE, &dwOldProtect)) { - *(CHAR*)lpAddress = (BYTE)0xE8; - *(DWORD*)((DWORD)lpAddress + 1) = (DWORD)lpProc - ((DWORD)lpAddress + 5); - - VirtualProtect(lpAddress, 5, dwOldProtect, NULL); - - return true; - } - - return false; -} - -inline bool call(DWORD dwAddress, LPVOID lpProc) { - return call((LPVOID)dwAddress, lpProc); -} - -inline bool jmp(LPVOID lpAddress, LPVOID lpDestination) { - DWORD dwOldProtect; - - if (VirtualProtect(lpAddress, 5, PAGE_EXECUTE_READWRITE, &dwOldProtect)) { - *(CHAR*)lpAddress = (BYTE)0xE9; - *(DWORD*)((DWORD)lpAddress + 1) = (DWORD)lpDestination - ((DWORD)lpAddress + 5); - - VirtualProtect(lpAddress, 5, dwOldProtect, NULL); - - return true; - } - - return false; -} - -inline bool jmp(DWORD dwAddress, DWORD lpDestination) { - return jmp((LPVOID)dwAddress, (LPVOID)lpDestination); -} \ No newline at end of file diff --git a/Src Backup/Variables.h b/Src Backup/Variables.h deleted file mode 100644 index b61c47a..0000000 --- a/Src Backup/Variables.h +++ /dev/null @@ -1,76 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "fcalls.h" -#include "JassNatives.h" -#include "JassMachine.h" -#include "FrameAPI.h" - -#define WAR3_LUA_MAJOR "1" -#define WAR3_LUA_MINOR "1" -#define WAR3_LUA_RELEASE "4 (Beta)" - -#define WAR3_LUA_VERSION WAR3_LUA_MAJOR "." WAR3_LUA_MINOR "." WAR3_LUA_RELEASE -#define WAR3_LUA "War3 Lua " WAR3_LUA_VERSION - -#define GAME_ID "W3L" - -#define MakePtr(a, b) ((DWORD)a + (DWORD)b) - -static HMODULE gameBase = GetModuleHandle("game.dll"); - -enum OFFSETS { - _mapMPQ = 0xaae788, - - _jassEntryPoint = 0x3b0a90, - _jassEntryPointProc = 0x3b54b0, - _getInstanceProc = 0x4c34d0, - _overflowOpcodeProc = 0x45f79a, - _opcodeList = 0x45f808, - _opcodeListSize = 0x45ea4d, - _opcodeSwitch = 0x45ea5a, - - _jassNativesList = 0x3d4025, - - _getWarcraftID1 = 0x54f248, - _getWarcraftID2 = 0x54f24f, - - _netProvider = 0xacec10, - - _getGameUI = 0x300710, - _getGameWar3 = 0x75f0, - _getTooltipFrame = 0x337240, - - _stringHastTable = 0xacd214, - _FDFHashTable = 0xacd264, - _stringHashNodeGrowListArray = 0x5ca9b0, - _baseFrameHashNodeGrowListArray = 0x5d5650, - _readFDFFile = 0x5d8de0, - _CFrameDefStatus = 0xa8c804, - _getCFrameByName = 0x5fa970, - _createCFrame = 0x5c9560, - _setCFrameText = 0x611d40, - _setCFrameTextColor = 0x611590, - _getCFrameTextHeight = 0x6118a0, - // _getCLayoutFrameWidth = 0x604fb0, - // _getCLayoutFrameHeight = 0x604fa0, - _setCLayoutFrameScale = 0x605d40, - _setCLayoutFramePoint = 0x606770, - _clearCLayoutFrameAllPoints = 0x606270, - _setCLayoutFrameWidth = 0x605d90, - _setCLayoutFrameHeight = 0x605db0, - _setCLayoutFrameAbsolutePoint = 0x6061b0, - _setCLayoutFrameCageMouse = 0x604fc0, - _setCLayoutFrameAllPoints = 0x6067f0, - - _frameevent_control_click = 0xa9a86c, - _frameevent_control_mouseenter = 0xa9a84c -}; - -extern std::map jassnatives; -extern std::map triggers; -extern std::unordered_map> frameEventHashTable; -extern bool running; \ No newline at end of file diff --git a/Src Backup/Warcraft.cpp b/Src Backup/Warcraft.cpp deleted file mode 100644 index 6a4856b..0000000 --- a/Src Backup/Warcraft.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "Warcraft.h" - -#include "Variables.h" -#include "fcalls.h" -#include "Mem.h" - -PJASS_INSTANCE getJassMachine(DWORD index) { - DWORD jass_thread = *(DWORD*)(*(DWORD*)(getInstance(5) + 0x90) + index * 4); - - return jass_thread ? (PJASS_INSTANCE)jass_thread : NULL; -} - -PJASS_INSTANCE getJassInstance() { - DWORD instance = getInstance(5); - - return *(DWORD*)(instance + 0x14) ? *(PJASS_INSTANCE*)(*(DWORD*)(instance + 0xc) + *(DWORD*)(instance + 0x14) * 4 - 4) : NULL; -} - -DWORD getInstance(DWORD index) { - return fastcall(MakePtr(gameBase, _getInstanceProc), index); -} - -CGameUI* GetGameUI(UINT unknown0, UINT unknown1) { - return fastcall(MakePtr(gameBase, _getGameUI), unknown0, unknown1); -} - -CGameWar3* GetGameWar3(UINT unknown0) { - return fastcall(MakePtr(gameBase, _getGameWar3), unknown0); -} \ No newline at end of file diff --git a/Src Backup/Warcraft.h b/Src Backup/Warcraft.h deleted file mode 100644 index be7ebab..0000000 --- a/Src Backup/Warcraft.h +++ /dev/null @@ -1,1345 +0,0 @@ -#pragma once - -#include - -#ifndef _Warcraft_h -#define _Warcraft_h -typedef struct { - DWORD unk; - DWORD max_size; - DWORD array; - - UINT32 get(DWORD index) { - DWORD result = 0; - - if (index < max_size) { - result = array + 0x10 * index; - ++* (UINT32*)(result + 0xC); - } - - return result; - } - -} STRING_TABLE, * PSTRING_TABLE; - -typedef struct { - BYTE unk[4]; - DWORD counter; - DWORD* codes; // max_size = 1024 - - DWORD push_code(DWORD address) { - codes[counter] = address; - - return counter++; - } - - DWORD Size() { - return counter; - } -} CODE_TABLE, * PCODE_TABLE; - -typedef struct { - BYTE rettype; - BYTE type; - BYTE reg; - BYTE opcode; - DWORD value; -} JASS_OPCODE, * PJASS_OPCODE; - -typedef struct { - BYTE unk0[0x20]; - PJASS_OPCODE opcode; - BYTE unk1[0x10]; - UINT has_sleep; - BYTE unk2[0x2818]; - DWORD index; - BYTE unk3[0x20]; - PSTRING_TABLE string_table; - BYTE unk4[0x10]; - PCODE_TABLE code_table; - BYTE unk5[0x1C]; -} JASS_INSTANCE, * PJASS_INSTANCE; - -typedef struct { - BYTE unk0[18]; - char access_key[12]; - DWORD wacraft_key; - char language_ltype[8]; - BYTE unk1[8]; - DWORD language_key[8]; - char language[8]; - -} NetProviderLTCP, *PNetProviderLTCP; - -typedef struct { - int VirtualTable; - int field0004; - int field0008; - int field000C; - int field0010; - int field0014; - int field0018; - int field001C; - int field0020; - int field0024; - int field0028; - int field002C; - int field0030; - int field0034; - int field0038; - int field003C; - int field0040; - int field0044; - int field0048; - int field004C; - int field0050; - int field0054; - int field0058; - int field005C; - int field0060; - int field0064; - int field0068; - int field006C; - int field0070; - int field0074; - int field0078; - int field007C; - int field0080; - int field0084; - int field0088; - int field008C; - int field0090; - int field0094; - int field0098; - int field009C; - int field00A0; - int field00A4; - int field00A8; - int field00AC; - int field00B0; -} CFrame, * PCFrame; -#define FRAMELAYOUT(f) ((UINT)f + sizeof(CFrame)) - -struct CGameUI : CFrame { - int VirtualTable; - int field00B8; - int field00BC; - int field00C0; - int field00C4; - int field00C8; - int field00CC; - int field00D0; - int field00D4; - int field00D8; - int field00DC; - int field00E0; - int field00E4; - int field00E8; - int field00EC; - int field00F0; - int field00F4; - int field00F8; - int field00FC; - int field0100; - int field0104; - int field0108; - int field010C; - int field0110; - int field0114; - int field0118; - int field011C; - int field0120; - int field0124; - int field0128; - int field012C; - int field0130; - int field0134; - int field0138; - int field013C; - int field0140; - int field0144; - int field0148; - int field014C; - int field0150; - int field0154; - int field0158; - int field015C; - int field0160; - int field0164; - int field0168; - int field016C; - int field0170; - int field0174; - int field0178; - int field017C; - int field0180; - int field0184; - int field0188; - int field018C; - int field0190; - int field0194; - int field0198; - int field019C; - int field01A0; - int field01A4; - int field01A8; - int isUserInputEnabled; - int isUserInterfaceEnabled; - int field01B4; - int field01B8; - int field01BC; - int field01C0; - int field01C4; - int field01C8; - int field01CC; - int field01D0; - int field01D4; - int field01D8; - int field01DC; - int field01E0; - int field01E4; - int field01E8; - int field01EC; - int field01F0; - int field01F4; - int field01F8; - int field01FC; - int field0200; - int field0204; - int field0208; - int field020C; - int field0210; - int field0214; - int field0218; - int field021C; - int field0220; - int field0224; - int field0228; - int field022C; - int field0230; - int field0234; - int field0238; - int field023C; - int field0240; - int field0244; - int field0248; - int field024C; - int field0250; - int Camera; - int isInGameMenu; - int field025C; - int isGamePaused; - int field0264; - int field0268; - int field026C; - int field0270; - int field0274; - int field0278; - int field027C; - int field0280; - int field0284; - int field0288; - int field028C; - int isDragSelectionEnabled; - int isDragSelectionVisible; - int isPreSelectionEnabled; - int isPreSelectionVisible; - int isSelectionEnabled; - int isSelectionVisible; - int field02A8; - int field02AC; - int field02B0; - int field02B4; - int field02B8; - int field02BC; - int field02C0; - int field02C4; - int field02C8; - int field02CC; - int field02D0; - int field02D4; - int field02D8; - int field02DC; - int field02E0; - int field02E4; - int field02E8; - int field02EC; - int field02F0; - int field02F4; - int field02F8; - int field02FC; - int field0300; - int field0304; - int field0308; - int field030C; - float MouseWorldX; // Use from WorldFrame - float MouseWorldY; - float MouseWorldZ; - int field031C; - int field0320; - int field0324; - int field0328; - int field032C; - int field0330; - int field0334; - int field0338; - int field033C; - int field0340; - int field0344; - int field0348; - int field034C; - int field0350; - int field0354; - int field0358; - int field035C; - int field0360; - int field0364; - int field0368; - int field036C; - int field0370; - int field0374; - int field0378; - int field037C; - int field0380; - int field0384; - int field0388; - int field038C; - int field0390; - int field0394; - int field0398; - int field039C; - int field03A0; - int field03A4; - int field03A8; - int field03AC; - int field03B0; - int field03B4; - int field03B8; - CGameUI* WorldFrameWar3; // CWorldFrameWar3* - CGameUI* Minimap; // CFrame* - CGameUI* InfoBar; - CGameUI* CommandBar; - CGameUI* ResourceBarFrame; - CGameUI* UpperButtonBarFrame; - int field03D4; - CGameUI* ClickableBlock; - CGameUI* HeroBar; - CGameUI* PeonBar; - CGameUI* Message; // CSimpleMessageFrame* - CGameUI* UnitMessage; // CSimpleMessageFrame* - CGameUI* ChatMessage; // CSimpleMessageFrame* - CGameUI* TopMessage; // CSimpleMessageFrame* - CGameUI* Portrait; // CFrame* - CGameUI* TimeOfDayIndicator; // CFrame* - CGameUI* ChatEditBar; - CGameUI* CinematicPanel; - int field0404; - CGameUI* MinimapButtons[5]; - CGameUI* FrameB; // CFrame* - CGameUI* MouseBorders; - CGameUI* FrameA; // CFrame* - CGameUI* SimpleConsole; - int QuickSaveHotKey; - int QuickLoadHotKey; - int QuickHelpHotKey; - int QuickOptionsHotKey; - int QuickQuitHotKey; - int MinimapSignalHotKey; - int MinimapTerrainHotKey; - int MinimapColorsHotKey; - int MinimapCreepsHotKey; - int FormationToggleHotKey; -}; - -struct CGameWar3 { - int field0000; // Pointer - int field0004; - int field0008; - int field000C; - int field0010; - int field0014; // Pointer - int field0018; - int field001C; // CGameState - int field0020; // CGameIdMaps - int field0024; - int field0028; - int field002C; - int field0030; // CMapSetupWar3 - int field0034; // CFogOfWarMap - int field0038; // Pointer - int field003C; - int field0040; // CStringRep - int field0044; - int field0048; - int field004C; - int field0050; - int field0054; - int field0058; // CPlayerWar3 - int field005C; // CPlayerWar3 - int field0060; // CPlayerWar3 - int field0064; // CPlayerWar3 - int field0068; // CPlayerWar3 - int field006C; // CPlayerWar3 - int field0070; // CPlayerWar3 - int field0074; // CPlayerWar3 - int field0078; // CPlayerWar3 - int field007C; // CPlayerWar3 - int field0080; // CPlayerWar3 - int field0084; // CPlayerWar3 - int field0088; // CPlayerWar3 - int field008C; // CPlayerWar3 - int field0090; // CPlayerWar3 - int field0094; // CPlayerWar3 - int field0098; // 16 - int field009C; // 12 - int field00A0; // Pointer - int field00A4; - int field00A8; // 12 - float field00AC; // 320 - float field00B0; // -3264 - int field00B4; - int field00B8; - int field00BC; // Pointer - int field00C0; - int field00C4; - int field00C8; - int field00CC; - int field00D0; - int field00D4; - float field00D8; // -192 - float field00DC; // 2304 - int field00E0; - int field00E4; - int field00E8; // Pointer - int field00EC; - int field00F0; - int field00F4; - int field00F8; - int field00FC; - int field0100; - int field0104; - int field0108; - int field010C; - int field0110; - int field0114; - int field0118; - int field011C; - int field0120; - int field0124; - int field0128; - int field012C; - int field0130; - int field0134; - int field0138; - int field013C; - int field0140; - int field0144; - int field0148; - int field014C; - int field0150; - int field0154; - int field0158; - int field015C; - int field0160; - int field0164; - int field0168; - int field016C; - int field0170; - int field0174; - int field0178; - int field017C; - int field0180; - int field0184; - int field0188; - int field018C; - int field0190; - int field0194; - int field0198; - int field019C; - int field01A0; - int field01A4; - int field01A8; - int field01AC; - int field01B0; - int field01B4; - int field01B8; - int field01BC; - int field01C0; - int field01C4; - int field01C8; - int field01CC; - int field01D0; - int field01D4; - int field01D8; - int field01DC; - int field01E0; - int field01E4; - int field01E8; - int field01EC; - int field01F0; - int field01F4; - int field01F8; - int field01FC; - int field0200; - int field0204; - int field0208; - int field020C; - int field0210; - int field0214; - int field0218; - int field021C; - int field0220; - int field0224; - int field0228; - int field022C; - int field0230; - int field0234; - int field0238; - int field023C; - int field0240; - int field0244; - int field0248; - int field024C; - int field0250; - int field0254; - int field0258; - int field025C; - int field0260; - int field0264; - int field0268; - int field026C; - int field0270; - int field0274; - int field0278; - int field027C; - int field0280; - int field0284; - int field0288; - int field028C; - int field0290; - int field0294; - int field0298; - int field029C; - int field02A0; - int field02A4; - int field02A8; - int field02AC; - int field02B0; - int field02B4; - int field02B8; - int field02BC; - int field02C0; - int field02C4; - int field02C8; - int field02CC; - int field02D0; - int field02D4; - float field02D8; // -0.0000232331422 - int field02DC; - int field02E0; - BYTE field02E4; // 157 - BYTE field02E5; // 92 - BYTE field02E6; // 101 - BYTE field02E7; // 111 - float field02E8; // -0.003639792325 - int field02EC; // Pointer - int field02F0; // Pointer - int field02F4; - int field02F8; // CStringRep - int field02FC; // Pointer - int field0300; - int field0304; // CStringRep - int field0308; // Pointer - int field030C; - int field0310; // CStringRep - int field0314; // Pointer - int field0318; - int field031C; // CStringRep - int field0320; - int field0324; - int field0328; - int field032C; - int field0330; - int field0334; - int field0338; - int field033C; - int field0340; - int field0344; - int field0348; - int field034C; - int field0350; - int field0354; - int field0358; - int field035C; - int field0360; - int field0364; - int field0368; - int field036C; - int field0370; - int field0374; - int field0378; - int field037C; - int field0380; - int field0384; - int field0388; - int field038C; - int field0390; - int field0394; - int field0398; - int field039C; - int field03A0; - int field03A4; - int field03A8; - int field03AC; - int field03B0; - int field03B4; - int field03B8; - int field03BC; - int field03C0; - int field03C4; - int field03C8; - int field03CC; // Pointer - int field03D0; - int field03D4; // CStringRep - int field03D8; - int field03DC; - int field03E0; - int field03E4; - int field03E8; - int field03EC; // Pointer - int field03F0; - int field03F4; - int field03F8; - int field03FC; - int field0400; // CGameCacheManager - int field0404; // CGameHashTableManager - int field0408; - int field040C; - int field0410; - int field0414; - int field0418; - int field041C; - int field0420; - int field0424; - int field0428; - int field042C; - int field0430; - int field0434; - int field0438; - int field043C; - int field0440; - int field0444; - int field0448; - int field044C; - int field0450; - int field0454; - int field0458; - int field045C; - int field0460; - int field0464; - int field0468; - int field046C; - int field0470; - int field0474; - int field0478; - int field047C; - int field0480; - int field0484; - int field0488; - int field048C; - int field0490; - int field0494; - int field0498; - int field049C; - int field04A0; - int field04A4; - int field04A8; - int field04AC; - int field04B0; - int field04B4; - int field04B8; - int field04BC; - int field04C0; - int field04C4; - int field04C8; - int field04CC; - int field04D0; - int field04D4; - int field04D8; - int field04DC; - int field04E0; - int field04E4; - int field04E8; - int field04EC; - int field04F0; - int field04F4; - int field04F8; - int field04FC; - int field0500; - int field0504; - int field0508; - int field050C; - int field0510; - int field0514; - int field0518; - int field051C; - int field0520; - int field0524; - int field0528; - int field052C; - int field0530; - int field0534; - int field0538; - int field053C; - int field0540; - int field0544; - int field0548; - int field054C; - int field0550; - int field0554; - int field0558; - int field055C; - int field0560; - int field0564; - int field0568; - int field056C; - int field0570; - int field0574; - int field0578; - int field057C; - int field0580; - int field0584; - int field0588; - int field058C; - int field0590; - int field0594; - int field0598; - int field059C; - int field05A0; - int field05A4; - int field05A8; - int field05AC; - int field05B0; - int field05B4; - int field05B8; - int field05BC; - int field05C0; - int field05C4; - int field05C8; - int field05CC; - int field05D0; - int field05D4; - int field05D8; - int field05DC; - int field05E0; - int field05E4; - int field05E8; - int field05EC; - int field05F0; - int field05F4; - int field05F8; - int field05FC; - int field0600; - int field0604; - int field0608; - int field060C; - int field0610; - int field0614; - int field0618; - int field061C; - int field0620; - int field0624; - int field0628; - int field062C; - int field0630; - int field0634; - int field0638; - int field063C; - int field0640; - int field0644; - int field0648; - int field064C; - int field0650; - int field0654; - int field0658; - int field065C; - int field0660; - int field0664; - int field0668; - int field066C; - int field0670; - int field0674; - int field0678; - int field067C; - int field0680; - int field0684; - int field0688; - int field068C; - int field0690; - int field0694; - int field0698; - int field069C; - int field06A0; - int field06A4; - int field06A8; - int field06AC; - int field06B0; - int field06B4; - int field06B8; - int field06BC; - int field06C0; - int field06C4; - int field06C8; - int field06CC; - int field06D0; - int field06D4; - int field06D8; - int field06DC; - int field06E0; - int field06E4; - int field06E8; - int field06EC; - int field06F0; - int field06F4; - int field06F8; - int field06FC; - int field0700; - int field0704; - int field0708; - int field070C; - int field0710; - int field0714; - int field0718; - int field071C; - int field0720; - int field0724; - int field0728; - int field072C; - int field0730; - int field0734; - int field0738; - int field073C; - int field0740; - int field0744; - int field0748; - int field074C; - int field0750; - int field0754; - int field0758; - int field075C; - int field0760; - int field0764; - int field0768; - int field076C; - int field0770; - int field0774; - int field0778; - int field077C; - int field0780; - int field0784; - int field0788; - int field078C; - int field0790; - int field0794; - int field0798; - int field079C; - int field07A0; - int field07A4; - int field07A8; - int field07AC; - int field07B0; - int field07B4; - int field07B8; - int field07BC; - int field07C0; - int field07C4; - int field07C8; - int field07CC; - int field07D0; - int field07D4; - int field07D8; - int field07DC; - int field07E0; - int field07E4; - int field07E8; - int field07EC; - int field07F0; - int field07F4; - int field07F8; - int field07FC; - int field0800; - int field0804; - int field0808; - int field080C; - int field0810; - int field0814; - int field0818; - int field081C; - int field0820; - int field0824; - int field0828; - int field082C; - int field0830; - int field0834; - int field0838; - int field083C; - int field0840; - int field0844; - int field0848; - int field084C; - int field0850; - int field0854; - int field0858; - int field085C; - int field0860; - int field0864; - int field0868; - int field086C; - int field0870; - int field0874; - int field0878; - int field087C; - int field0880; - int field0884; - int field0888; - int field088C; - int field0890; - int field0894; - int field0898; - int field089C; - int field08A0; - int field08A4; - int field08A8; - int field08AC; - int field08B0; - int field08B4; - int field08B8; - int field08BC; - int field08C0; - int field08C4; - int field08C8; - int field08CC; - int field08D0; - int field08D4; - int field08D8; - int field08DC; - int field08E0; - int field08E4; - int field08E8; - int field08EC; - int field08F0; - int field08F4; - int field08F8; - int field08FC; - int field0900; - int field0904; - int field0908; - int field090C; - int field0910; - int field0914; - int field0918; - int field091C; - int field0920; - int field0924; - int field0928; - int field092C; - int field0930; - int field0934; - int field0938; - int field093C; - int field0940; - int field0944; - int field0948; - int field094C; - int field0950; - int field0954; - int field0958; - int field095C; - int field0960; - int field0964; - int field0968; - int field096C; - int field0970; - int field0974; - int field0978; - int field097C; - int field0980; - int field0984; - int field0988; - int field098C; - int field0990; - int field0994; - int field0998; - int field099C; - int field09A0; - int field09A4; - int field09A8; - int field09AC; - int field09B0; - int field09B4; - int field09B8; - int field09BC; - int field09C0; - int field09C4; - int field09C8; - int field09CC; - int field09D0; - int field09D4; - int field09D8; - int field09DC; - int field09E0; - int field09E4; - int field09E8; - int field09EC; - int field09F0; - int field09F4; - int field09F8; - int field09FC; - int field0A00; - int field0A04; - int field0A08; - int field0A0C; - int field0A10; - int field0A14; - int field0A18; - int field0A1C; - int field0A20; - int field0A24; - int field0A28; - int field0A2C; - int field0A30; - int field0A34; - int field0A38; - int field0A3C; - int field0A40; - int field0A44; - int field0A48; - int field0A4C; - int field0A50; - int field0A54; - int field0A58; - int field0A5C; - int field0A60; - int field0A64; - int field0A68; - int field0A6C; - int field0A70; - int field0A74; - int field0A78; - int field0A7C; - int field0A80; - int field0A84; - int field0A88; - int field0A8C; - int field0A90; - int field0A94; - int field0A98; - int field0A9C; - int field0AA0; - int field0AA4; - int field0AA8; - int field0AAC; - int field0AB0; - int field0AB4; - int field0AB8; - int field0ABC; - int field0AC0; - int field0AC4; - int field0AC8; - int field0ACC; - int field0AD0; - int field0AD4; - int field0AD8; - int field0ADC; - int field0AE0; - int field0AE4; - int field0AE8; - int field0AEC; - int field0AF0; - int field0AF4; - int field0AF8; - int field0AFC; - int field0B00; - int field0B04; - int field0B08; - int field0B0C; - int field0B10; - int field0B14; - int field0B18; - int field0B1C; - int field0B20; - int field0B24; - int field0B28; - int field0B2C; - int field0B30; - int field0B34; - int field0B38; - int field0B3C; - int field0B40; - int field0B44; - int field0B48; - int field0B4C; - int field0B50; - int field0B54; - int field0B58; - int field0B5C; - int field0B60; - int field0B64; - int field0B68; - int field0B6C; - int field0B70; - int field0B74; - int field0B78; - int field0B7C; - int field0B80; - int field0B84; - int field0B88; - int field0B8C; - int field0B90; - int field0B94; - int field0B98; - int field0B9C; - int field0BA0; - int field0BA4; - int field0BA8; - int field0BAC; - int field0BB0; - int field0BB4; - int field0BB8; - int field0BBC; - int field0BC0; - int field0BC4; - int field0BC8; - int field0BCC; - int field0BD0; - int field0BD4; - int field0BD8; - int field0BDC; - int field0BE0; - int field0BE4; - int field0BE8; - int field0BEC; - int field0BF0; - int field0BF4; - int field0BF8; - int field0BFC; - int field0C00; - int field0C04; - int field0C08; - int field0C0C; - int field0C10; - int field0C14; - int field0C18; - int field0C1C; - int field0C20; - int field0C24; - int field0C28; - int field0C2C; - int field0C30; - int field0C34; - int field0C38; - int field0C3C; - int field0C40; - int field0C44; - int field0C48; - int field0C4C; - int field0C50; - int field0C54; - int field0C58; - int field0C5C; - int field0C60; - int field0C64; - int field0C68; - int field0C6C; - int field0C70; - int field0C74; - int field0C78; - int field0C7C; - int field0C80; - int field0C84; - int field0C88; - int field0C8C; - int field0C90; - int field0C94; - int field0C98; - int field0C9C; - int field0CA0; - int field0CA4; - int field0CA8; - int field0CAC; - int field0CB0; - int field0CB4; - int field0CB8; - int field0CBC; - int field0CC0; - int field0CC4; - int field0CC8; - int field0CCC; - int field0CD0; - int field0CD4; - int field0CD8; - int field0CDC; - int field0CE0; - int field0CE4; - int field0CE8; - int field0CEC; - int field0CF0; - int field0CF4; - int field0CF8; - int field0CFC; - int field0D00; - int field0D04; - int field0D08; - int field0D0C; - int field0D10; - int field0D14; - int field0D18; - int field0D1C; - int field0D20; - int field0D24; - int field0D28; - int field0D2C; - int field0D30; - int field0D34; - int field0D38; - int field0D3C; - int field0D40; - int field0D44; - int field0D48; - int field0D4C; - int field0D50; - int field0D54; - int field0D58; - int field0D5C; - int field0D60; - int field0D64; - int field0D68; - int field0D6C; - int field0D70; - int field0D74; - int field0D78; - int field0D7C; - int field0D80; - int field0D84; - int field0D88; - int field0D8C; - int field0D90; - int field0D94; - int field0D98; - int field0D9C; - int field0DA0; - int field0DA4; - int field0DA8; - int field0DAC; - int field0DB0; - int field0DB4; - int field0DB8; - int field0DBC; - int field0DC0; - int field0DC4; - int field0DC8; - int field0DCC; - int field0DD0; - int field0DD4; - int field0DD8; - int field0DDC; - int field0DE0; - int field0DE4; - int field0DE8; - int field0DEC; - int field0DF0; - int field0DF4; - int field0DF8; - int field0DFC; - int field0E00; - int field0E04; - int field0E08; - int field0E0C; - int field0E10; - int field0E14; - int field0E18; - int field0E1C; - int field0E20; - int field0E24; - int field0E28; - int field0E2C; - int field0E30; - int field0E34; - int field0E38; - int field0E3C; - int field0E40; - int field0E44; - int field0E48; - int field0E4C; - int field0E50; - int field0E54; - int field0E58; - int field0E5C; - int field0E60; - int field0E64; - int field0E68; - int field0E6C; - int field0E70; - int field0E74; - int field0E78; - int field0E7C; - int field0E80; - int field0E84; - int field0E88; - int field0E8C; - int field0E90; - int field0E94; - int field0E98; - int field0E9C; - int field0EA0; - int field0EA4; - int field0EA8; - int field0EAC; - int field0EB0; - int field0EB4; - int field0EB8; - int field0EBC; - int field0EC0; - int field0EC4; - int field0EC8; - int field0ECC; - int field0ED0; - int field0ED4; - int field0ED8; - int field0EDC; - int field0EE0; - int field0EE4; - int field0EE8; - int field0EEC; - int field0EF0; - int field0EF4; - int field0EF8; - int field0EFC; - int field0F00; - int field0F04; - int field0F08; - int field0F0C; - int field0F10; - int field0F14; - int field0F18; - int field0F1C; - int field0F20; - int field0F24; - int field0F28; - int field0F2C; - int field0F30; - int field0F34; - int field0F38; - int field0F3C; -}; -#endif - -PJASS_INSTANCE getJassMachine(DWORD index = 1); - -PJASS_INSTANCE getJassInstance(); - -DWORD getInstance(DWORD index); - -CGameUI* GetGameUI(UINT unknown0 = NULL, UINT unknown1 = NULL); - -CGameWar3* GetGameWar3(UINT unknown0 = NULL); \ No newline at end of file diff --git a/Src Backup/WarcraftFunctions.cpp b/Src Backup/WarcraftFunctions.cpp deleted file mode 100644 index afaed07..0000000 --- a/Src Backup/WarcraftFunctions.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include "WarcraftFunctions.h" -#include "Warcraft.h" - -PVECTOR3 GetMouseWorldPos() { - CGameUI* gameUI = GetGameUI(); - - return gameUI ? (PVECTOR3)&gameUI->WorldFrameWar3->MouseWorldX : NULL; -} - -float GetMouseWorldX() { - PVECTOR3 mousePos = GetMouseWorldPos(); - - return mousePos ? mousePos->_x : 0.f; -} - -float GetMouseWorldY() { - PVECTOR3 mousePos = GetMouseWorldPos(); - - return mousePos ? mousePos->_y : 0.f; -} - -float GetMouseWorldZ() { - PVECTOR3 mousePos = GetMouseWorldPos(); - - return mousePos ? mousePos->_z : 0.f; -} - -UINT_PTR ConvertHandleToObject(UINT handle) { - return handle ? *(UINT_PTR*)(*(UINT_PTR*)((GetGameWar3()->field001C) + 0x19C) + handle * 0xC - 0x2FFFFF * 4) : NULL; -} - -PVECTOR3 GetObjectPos(UINT_PTR object) { - return object ? (PVECTOR3)(*(UINT_PTR*)(object + 0x28) + 0xC0) : NULL; -} - -float GetObjectX(UINT_PTR object) { - PVECTOR3 objectPos = GetObjectPos(object); - - return objectPos ? objectPos->_x : 0.f; -} - -float GetObjectY(UINT_PTR object) { - PVECTOR3 objectPos = GetObjectPos(object); - - return objectPos ? objectPos->_y : 0.f; -} - -float GetObjectZ(UINT_PTR object) { - PVECTOR3 objectPos = GetObjectPos(object); - - return objectPos ? objectPos->_z : 0.f; -} - -void SetObjectPos(UINT_PTR object, const VECTOR3& pos) { - PVECTOR3 objectPos = GetObjectPos(object); - - if (!objectPos) { - return; - } - - objectPos->operator=(pos); -} - -void SetObjectX(UINT_PTR object, float x) { - PVECTOR3 objectPos = GetObjectPos(object); - - if (!objectPos) { - return; - } - - objectPos->_x = x; -} - -void SetObjectY(UINT_PTR object, float y) { - PVECTOR3 objectPos = GetObjectPos(object); - - if (!objectPos) { - return; - } - - objectPos->_y = y; -} - -void SetObjectZ(UINT_PTR object, float z) { - PVECTOR3 objectPos = GetObjectPos(object); - - if (!objectPos) { - return; - } - - objectPos->_z = z; -} \ No newline at end of file diff --git a/Src Backup/WarcraftFunctions.h b/Src Backup/WarcraftFunctions.h deleted file mode 100644 index 6079cdc..0000000 --- a/Src Backup/WarcraftFunctions.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include - -#ifndef _WarcraftFunctions_h -#define _WarcraftFunctions_h -typedef struct VECTOR3 { - VECTOR3(float x, float y, float z) : _x(x), _y(y), _z(z) {} - VECTOR3& operator=(const VECTOR3& from) { - if (this == &from) { - return *this; - } - - this->_x = from._x; - this->_y = from._y; - this->_z = from._z; - - return *this; - } - float _x; - float _y; - float _z; -} * PVECTOR3, * LPVECTOR3; -#endif - -PVECTOR3 GetMouseWorldPos(); -float GetMouseWorldX(); -float GetMouseWorldY(); -float GetMouseWorldZ(); - -UINT_PTR ConvertHandleToObject(UINT handle); - -PVECTOR3 GetObjectPos(UINT_PTR object); -float GetObjectX(UINT_PTR object); -float GetObjectY(UINT_PTR object); -float GetObjectZ(UINT_PTR object); - -void SetObjectPos(UINT_PTR object, const VECTOR3& pos); -void SetObjectX(UINT_PTR object, float x); -void SetObjectY(UINT_PTR object, float y); -void SetObjectZ(UINT_PTR object, float z); \ No newline at end of file diff --git a/Src Backup/fcalls.h b/Src Backup/fcalls.h deleted file mode 100644 index fc194a2..0000000 --- a/Src Backup/fcalls.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -template -inline R stdcall(F function, A...args) { - return reinterpret_cast(function)(args...); -} - -template -inline R fastcall(F function, A...args) { - return reinterpret_cast(function)(args...); -} - -template -inline R thiscall(F function, T _this, A...args) { - return reinterpret_cast(function)(_this, NULL, args...); -} \ No newline at end of file diff --git a/Src/Main.cpp b/Src/DllMain.cpp similarity index 68% rename from Src/Main.cpp rename to Src/DllMain.cpp index 1e996c8..b7ef24b 100644 --- a/Src/Main.cpp +++ b/Src/DllMain.cpp @@ -1,19 +1,17 @@ -#include -#include -#include -#include "Global.h" -#include "lua.h" -#include "JassNatives.h" +#include "pch.h" #include "JassMachine.h" +#include "JassNatives.h" #include "Hooks.h" -#include "Utils.h" +#include "Logger.h" +#include "EasterEgg.h" -bool consoleMode = false; bool developerMode = false; +SYSTEMTIME date; +std::string celebratingText; -bool startUp(); +bool StartUp(); -//----------------------------------------------------------------------------- +//--------------------------------------------------------------------- BOOL APIENTRY DllMain(HMODULE module, UINT reason, LPVOID reserved) { switch (reason) { @@ -21,26 +19,25 @@ BOOL APIENTRY DllMain(HMODULE module, UINT reason, LPVOID reserved) { if (!gameBase) { return FALSE; } - - DisableThreadLibraryCalls(module); - if (!startUp()) { + if (!StartUp()) { return FALSE; } - if (consoleMode) { - system("cls"); - } - printf("%s\n%s (%s)\n", LUA_COPYRIGHT, WAR3_LUA, WAR3_LUA_VERSION_NAME); + GetLocalTime(&date); + celebratingText = GetEasterText(date); + !celebratingText.empty() ? MessageBox(NULL, celebratingText.c_str(), "Celebration Message!", MB_ICONINFORMATION) : NULL; - jassNativesParse(); - jassOpcodeInitialize(); + JassMachine::JassOpcodeInitialize(); - attachHooks(); + Hooks::AttachHooks(); break; case DLL_PROCESS_DETACH: - detachHooks(); + + Hooks::DetachHooks(); + + Logger::CloseConsole(); break; } @@ -48,9 +45,9 @@ BOOL APIENTRY DllMain(HMODULE module, UINT reason, LPVOID reserved) { return TRUE; } -//----------------------------------------------------------------------------- +//--------------------------------------------------------------------- -bool startUp() { +bool StartUp() { DWORD handle; DWORD size = GetFileVersionInfoSize("game.dll", &handle); @@ -78,7 +75,10 @@ bool startUp() { } if (strstr(&cmdline[i + 1], "-console") || strstr(&cmdline[i + 1], "-debug")) { - consoleMode = openConsole(developerMode ? "Lua Console [Developer]" : "Lua Console") ? true : false; + Logger::OpenConsole(developerMode ? "Lua Console [Developer]" : "Lua Console"); + + system("cls"); + printf("%s\n%s (%s)\n\n", LUA_COPYRIGHT, WAR3_LUA, WAR3_LUA_VERSION_NAME); } return true; diff --git a/Src/EasterEgg.cpp b/Src/EasterEgg.cpp new file mode 100644 index 0000000..4e02344 --- /dev/null +++ b/Src/EasterEgg.cpp @@ -0,0 +1,54 @@ +#include "pch.h" +#include "EasterEgg.h" + +std::string GetEasterText(SYSTEMTIME& date) { + WORD day = date.wDay; + WORD month = date.wMonth; + std::string text = ""; + + if (day == 2 && month == 6 ) { + text = "~~~ Happy Birthday to Ev3nt! ~~~"; + } + + if (day == 1 && month == 1 ) { + text = "~~~ Happy New Year! ~~~"; + } + + if (day == 2 && month == 3 ) { + text = "~~~ Glory to Billy! ~~~"; + } + + if (day == 7 && month == 10 ) { + text = "~~~ Happy Birthday, the best president! ~~~"; + } + + if (day == 9 && month == 5 ) { + text = "~~~ Glory to the Red Army! ~~~"; + } + + if (day == 5 && month == 10 ) { + text = "~~~ Birthday of the best programming language! ~~~"; + } + + if (day == 16 && month == 12 ) { + text = "~~~ Happy Birthday, Warcraft III - Lua! ~~~"; + } + + if (day == 13 && month == 5 ) { + text = "~~~ Welcome to XGM! ~~~"; + } + + if (day == 24 && month == 10 ) { + text = "~~~ Three Hundred Bucks ~~~"; + } + + if (day == 6 && month == 5 ) { + text = "~~~ Quro started his work... ~~~"; + } + + if (day == 6 && month == 4) { + text = "~~~ Kokomi's day ~~~"; + } + + return text; +} \ No newline at end of file diff --git a/Src/EasterEgg.h b/Src/EasterEgg.h new file mode 100644 index 0000000..c9d7ec2 --- /dev/null +++ b/Src/EasterEgg.h @@ -0,0 +1,6 @@ +#pragma once + +#include +#include + +std::string GetEasterText(SYSTEMTIME& date); \ No newline at end of file diff --git a/Src/EasyStormLib/EasyStormLib.cpp b/Src/EasyStormLib/EasyStormLib.cpp new file mode 100644 index 0000000..84db052 --- /dev/null +++ b/Src/EasyStormLib/EasyStormLib.cpp @@ -0,0 +1,94 @@ +#include "../pch.h" +#include "EasyStormLib.h" +#include "StormLib.h" + +namespace Storm { + Archive::Archive() { + m_handle = NULL; + m_owner = false; + } + + Archive::~Archive() { + if (m_owner) { + Close(); + } + } + + void Archive::Open(std::string name, DWORD priority, DWORD flags) { + if (StormOpenArchive(name.c_str(), priority, flags, &m_handle)) { + m_owner = true; + } + } + + void Archive::Connect(HANDLE handle) { + m_handle = handle; + m_owner = false; + } + + void Archive::Close(bool force) { + if (m_owner || (!m_owner && force)) { + if (m_handle) { + StormCloseArchive(m_handle); + } + } + + m_handle = NULL; + } + + std::string Archive::GetArchiveName() { + char name[MAX_PATH]; + FillMemory(name, sizeof(name), 0); + + if (m_handle) { + StormGetArchiveName(m_handle, name, sizeof(name)); + } + + return name; + } + + std::string Archive::GetArchiveName(std::string fileName) { + char name[MAX_PATH]; + FillMemory(name, sizeof(name), 0); + + HANDLE _handle; + if (StormOpenFile(fileName.c_str(), &_handle)) { + HANDLE _archive; + if (StormGetFileArchive(_handle, &_archive)) { + StormGetArchiveName(_archive, name, sizeof(name)); + } + + StormCloseFile(_handle); + } + + return name; + } + + std::string Archive::operator[](std::string name) { + std::string filedata; + + HANDLE _handle = NULL; + + if (m_handle) { + StormOpenFileEx(m_handle, name.c_str(), 0, &_handle); + } + else { + StormOpenFile(name.c_str(), &_handle); + } + + if (_handle) { + SIZE_T high; // Idk how i can use it on x32, so maximum size limit is 4gb + SIZE_T size = StormGetFileSize(_handle, &high); + + SIZE_T readed; // Useless shit, cause we have checked file size + char* buffer = new char[size]; + FillMemory(buffer, size, 0); + StormReadFile(_handle, buffer, size, &readed, 0); + StormCloseFile(_handle); + + filedata.append(buffer, size); + delete[] buffer; + } + + return filedata; + } +} \ No newline at end of file diff --git a/Src/EasyStormLib/EasyStormLib.h b/Src/EasyStormLib/EasyStormLib.h new file mode 100644 index 0000000..84505c9 --- /dev/null +++ b/Src/EasyStormLib/EasyStormLib.h @@ -0,0 +1,23 @@ +#pragma once + +#include "../pch.h" + +namespace Storm { + class Archive { + public: + Archive(); + ~Archive(); // It's calling close if we're owner of archive + + void Open(std::string name, DWORD priority = 13, DWORD flags = 0); + void Connect(HANDLE handle); + + void Close(bool force = false); + std::string GetArchiveName(); + std::string GetArchiveName(std::string fileName); + + std::string operator[](std::string name); // Open file such as string + private: + HANDLE m_handle = NULL; + bool m_owner = false; // We're owner, if we have opened archive + }; +} \ No newline at end of file diff --git a/Src/EasyStormLib/StormLib.h b/Src/EasyStormLib/StormLib.h new file mode 100644 index 0000000..1c42ee3 --- /dev/null +++ b/Src/EasyStormLib/StormLib.h @@ -0,0 +1,16 @@ +#pragma once + +#include "../pch.h" + +HMODULE stormBase = LoadLibrary("storm.dll"); + +auto StormCloseArchive = (BOOL(WINAPI*)(HANDLE archive))(GetProcAddress(stormBase, (LPCSTR)252)); +auto StormCloseFile = (BOOL(WINAPI*)(HANDLE file))(GetProcAddress(stormBase, (LPCSTR)253)); +auto StormGetFileArchive = (SIZE_T(WINAPI*)(HANDLE file, HANDLE* archive))(GetProcAddress(stormBase, (LPCSTR)264)); +auto StormGetFileSize = (SIZE_T(WINAPI*)(HANDLE file, LPDWORD filesizehigh))(GetProcAddress(stormBase, (LPCSTR)265)); +auto StormOpenArchive = (BOOL(WINAPI*)(LPCSTR archivename, DWORD priority, DWORD flags, HANDLE* handle))(GetProcAddress(stormBase, (LPCSTR)266)); +auto StormOpenFileEx = (BOOL(WINAPI*)(HANDLE archive, LPCSTR filename, DWORD mode, HANDLE* handle))(GetProcAddress(stormBase, (LPCSTR)268)); +auto StormReadFile = (BOOL(WINAPI*)(HANDLE file, PVOID buffer, SIZE_T bumberofbytestoread, SIZE_T* read, LONG distancetomovehigh))(GetProcAddress(stormBase, (LPCSTR)269)); +auto StormGetArchiveName = (BOOL(WINAPI*)(HANDLE archive, LPSTR name, SIZE_T length))(GetProcAddress(stormBase, (LPCSTR)275)); +auto StormGetFileName = (BOOL(WINAPI*)(HANDLE file, LPSTR buffer, SIZE_T length))(GetProcAddress(stormBase, (LPCSTR)276)); +auto StormOpenFile = (BOOL(WINAPI*)(LPCSTR filename, HANDLE* file))(GetProcAddress(stormBase, (LPCSTR)267)); \ No newline at end of file diff --git a/Src/GameUI.cpp b/Src/GameUI.cpp deleted file mode 100644 index 4c0f6ca..0000000 --- a/Src/GameUI.cpp +++ /dev/null @@ -1,785 +0,0 @@ -#include "GameUI.h" -#include "Global.h" - -auto getGameUITrue = (CGameUI*(__fastcall*)(UINT, UINT))((UINT_PTR)gameBase + 0x300710); -auto getTooltipFrameTrue = (UINT(__fastcall*)(UINT))((UINT_PTR)gameBase + 0x337240); - -auto GrowStringHashNodeListArray = (void(__fastcall*)(LPVOID, UINT, DWORD))((UINT_PTR)gameBase + 0x5ca9b0); -auto GrowBaseFrameHashNodeListArray = (void(__fastcall*)(LPVOID, UINT, DWORD))((UINT_PTR)gameBase + 0x5d5650); -auto ReadFDFFile = (BOOL(__fastcall*)(LPCSTR, LPVOID, LPVOID, LPVOID))((UINT_PTR)gameBase + 0x5d8de0); - -auto GetCFrameByName = (UINT(__fastcall*)(LPCSTR, UINT))((UINT_PTR)gameBase + 0x5fa970); -auto CreateCFrame = (UINT(__fastcall*)(LPCSTR, UINT, EFramePoint, EFramePoint, UINT))((UINT_PTR)gameBase + 0x5c9560); -auto SetCTextFrameText = (void(__fastcall*)(UINT, UINT, LPCSTR))((UINT_PTR)gameBase + 0x611d40); -auto SetCFrameTextColor = (void(__fastcall*)(UINT, UINT, DWORD*))((UINT_PTR)gameBase + 0x611590); -auto GetCFrameTextHeight = (float(__fastcall*)(UINT))((UINT_PTR)gameBase + 0x6118a0); -auto SetCEditBoxText = (void(__fastcall*)(UINT, UINT, LPCSTR, UINT))((UINT_PTR)gameBase + 0x615B50); -auto SetCTextAreaText = (void(__fastcall*)(UINT, UINT, LPCSTR))((UINT_PTR)gameBase + 0x61E090); -auto SetCEditBoxFont = (void(__fastcall*)(UINT, UINT, LPCSTR, float, UINT))((UINT_PTR)gameBase + 0x613CA0); -auto SetCLayerFont = (void(__fastcall*)(UINT, UINT, LPCSTR, float, UINT))((UINT_PTR)gameBase + 0x5FB960); -auto SetCLayoutFrameWidth = (void(__fastcall*)(UINT, UINT, float))((UINT_PTR)gameBase + 0x605d90); -auto SetCLayoutFrameHeight = (void(__fastcall*)(UINT, UINT, float))((UINT_PTR)gameBase + 0x605db0); -auto SetCLayoutFrameScale = (void(__fastcall*)(UINT, UINT, float))((UINT_PTR)gameBase + 0x605d40); -auto SetCLayoutFramePoint = (void(__fastcall*)(UINT, UINT, EFramePoint, UINT, EFramePoint, float, float, UINT))((UINT_PTR)gameBase + 0x606770); -auto SetCSliderCurrentValue = (void(__fastcall*)(UINT, UINT, float, UINT))((UINT_PTR)gameBase + 0x61ee70); -auto SetCSimpleStatusBarTexture = (void(__fastcall*)(UINT, UINT, LPCSTR, BOOL))((UINT_PTR)gameBase + 0x60e610); -auto SetCSimpleStatusBarValue = (void(__fastcall*)(UINT, UINT, float))((UINT_PTR)gameBase + 0x60e430); -auto SetCSimpleStatusBarMinMaxValue = (void(__fastcall*)(UINT, UINT, float, float))((UINT_PTR)gameBase + 0x60e3b0); -//auto clearCLayoutFrameAllPoints = (void(__fastcall*)(UINT, UINT))((UINT_PTR)gameBase + 0x606270); -auto SetCLayoutFrameAbsolutePoint = (void(__fastcall*)(UINT, UINT, EFramePoint, float, float, UINT))((UINT_PTR)gameBase + 0x6061b0); -//auto setCLayoutFrameCageMouse = (void(__fastcall*)(UINT, UINT))((UINT_PTR)gameBase + 0x604fc0); -//auto setCLayoutFrameAllPoints = (void(__fastcall*)(UINT, UINT))((UINT_PTR)gameBase + 0x6067f0); -auto SetCBackDropFrameTexture = (void(__fastcall*)(UINT, UINT, LPCSTR, UINT, BOOL, UINT, UINT))((UINT_PTR)gameBase + 0x6212d0); -auto SetCSimpleTextureTexture = (void(__fastcall*)(UINT, UINT, LPCSTR, BOOL))((UINT_PTR)gameBase + 0x60e090); -auto SetCControlState = (void(__fastcall*)(UINT, UINT, BOOL))((UINT_PTR)gameBase + 0x336c20); -//auto SetCControlState = (void(__fastcall*)(UINT, UINT, BOOL))((UINT_PTR)gameBase + 0x601de0); -auto ClickCFrame = (void(__fastcall*)(UINT, UINT, UINT))((UINT_PTR)gameBase + 0x601f20); -auto AddCModelFrameModel = (void(__fastcall*)(UINT, UINT, LPCSTR, UINT))((UINT_PTR)gameBase + 0x6215d0); -auto SetCSpriteFrameArt = (void(__fastcall*)(UINT, UINT, LPCSTR, UINT, BOOL))((UINT_PTR)gameBase + 0x60f360); -auto SetCStatusBarArt = (void(__fastcall*)(UINT, UINT, LPCSTR, UINT))((UINT_PTR)gameBase + 0x6279a0); -auto SetCStatusBarMinMaxValue = (void(__fastcall*)(UINT, UINT, float, float))((UINT_PTR)gameBase + 0x6277c0); -auto DestroyCFrame = (void(__fastcall*)(UINT, UINT, UINT))((UINT_PTR)gameBase + 0x606910); -auto ShowCFrame = (void(__fastcall*)(UINT))((UINT_PTR)gameBase + 0x5fe690); -auto HideCFrame = (void(__fastcall*)(UINT))((UINT_PTR)gameBase + 0x5fe6f0); - -auto TriggerEvaluate = (BOOL(__cdecl*)(UINT))((UINT_PTR)gameBase + 0x3c3f80); -auto TriggerExecute = (BOOL(__cdecl*)(UINT))((UINT_PTR)gameBase + 0x3c3f40); - -int* pWheelState = (int*)((UINT_PTR)gameBase + 0xa9a844); - -const std::map> frameTypes = { - {BackdropFrame, {0x96f3f4, 0x96f3cc}}, - {ButtonFrame, {0x96f6fc, 0x96f6d4}}, - {ChatMode, {0x93a8bc, NULL}}, - {CommandButton, {0x93ebc4, NULL}}, - {CursorFrame, {0x97063c, 0x970610}}, - {EditBox, {0x96ecec, 0x96ecc0}}, - {Frame, {0x96deb4, 0x96de8c}}, - {FloatingFrame, {0x96fab4, 0x96fa88}}, - {GameUI, {0x93631c, 0x9362f4}}, - {HeroBarButton, {0x93f8dc, NULL}}, // 0x93F8BC ?? - {HighlightFrame, {0x96f974, 0x96f94c}}, - {LayoutFrame, {0x96de48, NULL}}, - {MessageFrame, {0x96f864, 0x96f83c}}, - {Minimap, {0x94002c, 0x940004}}, - {ModelFrame, {0x96f5ac, 0x96f584}}, - {PortraitButton, {0x9401e4, 0x9401bc}}, - {ScreenFrame, {0x96e07c, 0x96e054}}, - {SimpleButton, {0x96dc8c, NULL}}, - {SimpleFontString, {0x96e404, NULL}}, - {SimpleFrame, {0x96dfb4, NULL}}, - {SimpleGlueFrame, {0x96ee04, NULL}}, - {Uknown_1, {NULL, NULL}}, - {SimpleMessageFrame, {0x96dd84, NULL}}, - {Slider, {0x96f274, 0x96f24c}}, - {SpriteFrame, {0x96e584, 0x96e558}}, - {StatBar, {0x93e604, NULL}}, - {TextArea, {0x96efd4, 0x96efac}}, - {TextButtonFrame, {0x96f114, 0x96f0e8}}, - {TextFrame, {0x96e9b4, 0x96e988}}, - {UberToolTipWar3, {0x93f68c, NULL}}, - {WorldFrameWar3, {0x94157c, 0x941550}}, - {GlueButtonWar3, {0x95c92c, 0x95c900}}, - {GlueTextButtonWar3, {0x95a00c, 0x959fe0}}, - {GlueCheckBoxWar3, {0x95c7ec, 0x95c7c0}}, - {GluePopupMenuWar3, {0x959e84, 0x959e5c}}, - {GlueEditBoxWar3, {0x95cA6c, 0x95ca40}}, - {SlashChatBox, {0x95daec, 0x95dac4}}, - {TimerTextFrame, {0x95a564, 0x95a538}}, - {SimpleStatusBar, {0x96e48c, NULL}}, - {StatusBar, {0x970264, 0x97023c}}, - {UpperButtonBar, {0x93c3e4, 0x93c3c4}}, - {ResourceBar, {0x93d22c, NULL}}, - {SimpleConsole, {0x93bd2c, NULL}}, - {PeonBar, {0x93fc0c, 0x93fbf0}}, - {HeroBar, {0x93f974, NULL}}, // 0x93F958 - {TimeOfDayIndicator, {0x93fe64, 0x93fe38}}, - {InfoBar, {0x94066c, NULL}}, - {TimeCover, {0x93c054, 0x93c028}}, - {ProgressIndicator, {0x93834c, NULL}}, - {HeroLevelBar, {0x93fa24, NULL}}, - {BuildTimeIndicator, {0x93d684, NULL}}, - {InfoPanelDestructableDetail, {0x93ce54, NULL}}, - {InfoPanelItemDetail, {0x93b4c4, NULL}}, - {InfoPanelIconAlly, {0x93b374, NULL}}, - {InfoPanelIconHero, {0x93b284, NULL}}, - {InfoPanelIconGold, {0x93b20c, NULL}}, - {InfoPanelIconFood, {0x93b194, NULL}}, - {InfoPanelIconRank, {0x93b11c, NULL}}, - {InfoPanelIconArmor, {0x93b0a4, NULL}}, - {InfoPanelIconDamage, {0x93b02c, NULL}}, - {InfoPanelCargoDetail, {0x93cf8c, NULL}}, - {InfoPanelBuildingDetail, {0x93de9c, NULL}}, - {InfoPanelUnitDetail, {0x93cf0c, NULL}}, - {SimpleTexture, {0x96e440, NULL}} -}; // Type = {TypeAddress, LayoutAddress} - -const std::map frameEvents = { - {FRAMEEVENT_CONTROL_CLICK, 0x40090064}, - {FRAMEEVENT_MOUSE_MOVE, 0x40090066}, - {FRAMEEVENT_MOUSE_UP, 0x4009006a}, - {FRAMEEVENT_MOUSE_DOWN, NULL}, - {FRAMEEVENT_MOUSE_WHEEL, 0x4009006b}, - {FRAMEEVENT_CHECKBOX_CHECK, 0x400c0064}, - {FRAMEEVENT_EDITBOX_BUTTON_DOWN, 0x40060066}, - {FRAMEEVENT_POPUPMENU_ITEM_CHANGED, NULL}, - {FRAMEEVENT_MOUSE_DOUBLECLICK, NULL}, - {FRAMEEVENT_SPRITE_ANIM_UPDATE, NULL}, - {FRAMEEVENT_SLIDER_VALUE_CHANGED, 0x40100064}, - {FRAMEEVENT_DIALOG_CANCEL, NULL}, - {FRAMEEVENT_DIALOG_ACCEPT, NULL} -}; - -std::map> frameEventHashTable; - -std::vector frames; - -UINT triggerFrame = NULL; -EFrameEvent triggerEvent = FRAMEEVENT_NONE; - -PVOID pStringHastTable = (PVOID)((UINT_PTR)gameBase + 0xacd214); -PVOID pFDFHashTable = (PVOID)((UINT_PTR)gameBase + 0xacd264); -PVOID pCFrameDefaultStatus = (PVOID)((UINT_PTR)gameBase + 0xa8c804); - -EFrameEvent GetFrameEventType(UINT eventtype) { - for (const auto& frameEvent : frameEvents) { - if (frameEvent.second == eventtype) { - EFrameEvent event = (EFrameEvent)frameEvent.first; - - return event; - } - } - - return FRAMEEVENT_NONE; -} - -EFrameType GetFrameType(UINT frame) { - if (frame) { - UINT_PTR typeOffset = *(UINT*)frame - (UINT_PTR)gameBase; - - for (const auto& frameType : frameTypes) { - if (frameType.second.first == typeOffset || frameType.second.second == typeOffset) { - return frameType.first; - } - } - } - - return MissingFrame; -} - -UINT GetFrameLayout(UINT frame) { - if (!frame) { - return NULL; - } - - UINT_PTR typeOffset = *(UINT_PTR*)frame - (UINT_PTR)gameBase; - - for (const auto& frameType : frameTypes) { - if (frameType.second.first == typeOffset || frameType.second.second == typeOffset) { - return frameType.second.second ? (frame + 0xB4) : frame; - } - } - - return NULL; -} - -bool IsFrameLayout(UINT frame) { - if (!frame) { - return false; - } - - UINT_PTR typeOffset = *(UINT_PTR*)frame - (UINT_PTR)gameBase; - - for (const auto& frameType : frameTypes) { - if (frameType.second.first == typeOffset || frameType.second.second == typeOffset) { - return frameType.second.second == typeOffset; - } - } - - return false; -} - -CGameUI* GetGameUI(UINT unknown1, UINT unknown2) { - return getGameUITrue(unknown1, unknown2); -} - -UINT GetOriginFrame(EOriginFrame originframe, UINT index) { - CGameUI* gameui = GetGameUI(); - - switch (originframe) { - case ORIGIN_FRAME_GAME_UI: - return (UINT)gameui; - case ORIGIN_FRAME_WORLD_FRAME: - return (UINT)gameui->WorldFrameWar3; - case ORIGIN_FRAME_HERO_BAR: - return (UINT)gameui->HeroBar; - case ORIGIN_FRAME_HERO_BUTTON: - return (UINT)GetPanelButton((UINT)gameui->HeroBar, index, 0); - case ORIGIN_FRAME_HERO_HP_BAR: - return *(UINT*)((UINT)GetPanelButton((UINT)gameui->HeroBar, index, 0) + 0x1cc); - case ORIGIN_FRAME_HERO_MANA_BAR: - return *(UINT*)((UINT)GetPanelButton((UINT)gameui->HeroBar, index, 0) + 0x1d0); - case ORIGIN_FRAME_HERO_BUTTON_INDICATOR: - // Undefined - break; - case ORIGIN_FRAME_ITEM_BUTTON: - return *(UINT*)(*(UINT*)(*(UINT*)(gameui->InfoBar + 0x148) + 0x130) + 8 * index + 4); - case ORIGIN_FRAME_COMMAND_BUTTON: - return (UINT)GetPanelButton((UINT)gameui->CommandBar, index / 4, index % 4); - case ORIGIN_FRAME_SYSTEM_BUTTON: - // Undefined - break; - case ORIGIN_FRAME_PORTRAIT: - return (UINT)gameui->Portrait; - case ORIGIN_FRAME_MINIMAP: - return (UINT)gameui->Minimap; - case ORIGIN_FRAME_MINIMAP_BUTTON: - return (UINT)gameui->MinimapButtons[index]; - case ORIGIN_FRAME_TOOLTIP: - return GetTooltipFrame(); - case ORIGIN_FRAME_UBERTOOLTIP: - // Undefined - break; - case ORIGIN_FRAME_CHAT_MSG: - return (UINT)gameui->ChatMessage; - case ORIGIN_FRAME_UNIT_MSG: - return (UINT)gameui->UnitMessage; - case ORIGIN_FRAME_TOP_MSG: - return (UINT)gameui->TopMessage; - default: - break; - } - - return NULL; -} - -UINT GetPanelButton(UINT frame, BYTE row, BYTE column) { - return *(UINT*)(*(DWORD*)(16 * row + *((DWORD*)frame + 85) + 8) + 4 * column); -} - -UINT GetTooltipFrame(UINT unknown1) { - return getTooltipFrameTrue(unknown1); -} - -BOOL LoadTOCFile(LPCSTR filename) { - if (*(int*)((UINT_PTR)pStringHastTable + 0x14) < 0xFFFF) { - GrowStringHashNodeListArray(pStringHastTable, NULL, 0xFFFF); - } - - if (*(int*)((UINT_PTR)pFDFHashTable + 0x14) < 0xFFFF) { - GrowBaseFrameHashNodeListArray(pFDFHashTable, NULL, 0xFFFF); - } - - return ReadFDFFile(filename, pStringHastTable, pFDFHashTable, pCFrameDefaultStatus); -} - -UINT GetFrameByName(LPCSTR framename, UINT id) { - return GetCFrameByName(framename, id); -} - -UINT GetFrameParent(UINT frame) { - return GetFrameType(frame) ? (IsFrameLayout(frame) ? *(UINT*)(frame + 0x68) : *(UINT*)(frame + 0x20)) : NULL; -} - -UINT GetFrameChildrenCount(UINT frame) { - if (frame) { - UINT childtable = *(UINT*)(frame + 0x1c); - UINT i = 0; - - for (; (int)childtable > NULL; i++, childtable = *(UINT*)(childtable + 8)); - // for (; ReadProcessMemory(GetCurrentProcess(), (LPVOID)(childtable + 8), &childtable, sizeof(childtable), NULL); i++); - - return i; - } - - return NULL; - // return frame ? *(UINT*)(frame + 4) - 1 : NULL; ?? -} - -UINT GetFrameChild(UINT frame, UINT index) { - if (frame) { - UINT count = GetFrameChildrenCount(frame); - - if (count && index < count) { - UINT childtable = *(UINT*)(frame + 0x1c); - for (UINT i = 0; i < index; i++, childtable = *(UINT*)(childtable + 8)); - - return *(UINT*)(childtable + 0xc); - } - } - - return NULL; -} - -void TriggerRegisterFrameEvent(UINT trigger, UINT frame, EFrameEvent event) { - frameEventHashTable[frame][event] = trigger; -} - -UINT CreateFrame(LPCSTR baseframe, UINT parentframe, EFramePoint point, EFramePoint relativepoint) { - UINT prevframe = NULL; - - if (frames.size()) { - prevframe = frames[frames.size() - 1]; - } - - UINT frame = CreateCFrame(baseframe, parentframe, point, relativepoint, prevframe ? (IsFrameLayout(prevframe) ? *(UINT*)(prevframe + 0xB0) + 1 : *(UINT*)(prevframe + 0x164) + 1) : 0); - frames.push_back(frame); - - return frame; -} - -void SetFrameText(UINT frame, LPCSTR text) { - if (!frame) { - return; - } - - switch (GetFrameType(frame)) - { - case EditBox: - case GlueEditBoxWar3: - case SlashChatBox: - SetCEditBoxText(frame, NULL, text, 1); - - break; - case TextArea: - SetCTextAreaText(frame, NULL, text); - - break; - case TextButtonFrame: - case GlueTextButtonWar3: - frame = *(UINT*)(frame + 0x1e4); - case TextFrame: - case TimerTextFrame: - SetCTextFrameText(frame, NULL, text); - - break; - } -} - -LPCSTR GetFrameText(UINT frame) { - if (frame) { - switch (GetFrameType(frame)) - { - case EditBox: - case TextButtonFrame: - return *(LPCSTR*)(frame + 0x1e4); - case TextArea: - return *(LPCSTR*)(frame + 0x230); - case GlueTextButtonWar3: - frame = *(UINT*)(frame + 0x1e4); - case TextFrame: - return *(LPCSTR*)(frame + 0x1e8); - } - } - - return ""; -} - -void SetFrameTextColor(UINT frame, BYTE red, BYTE green, BYTE blue, BYTE alpha) { - if (!frame) { - return; - } - - DWORD color = ((alpha << 24) + (red << 16) + (green << 8) + blue); - - switch (GetFrameType(frame)) - { - case TextArea: - frame = *(UINT*)(frame + 0x230); - - break; - case TextButtonFrame: - case GlueTextButtonWar3: - frame = *(UINT*)(frame + 0x1e4); - case TextFrame: - break; - case EditBox: - SetCFrameTextColor(*(UINT*)(frame + 0x254), NULL, &color); - SetCFrameTextColor(*(UINT*)(frame + 0x258), NULL, &color); - default: - return; - } - - SetCFrameTextColor(frame, NULL, &color); -} - -float GetFrameTextHeight(UINT frame) { - if (frame) { - switch (GetFrameType(frame)) - { - case EditBox: - frame = *(UINT*)(frame + 0x254); - - break; - case TextArea: - frame = *(UINT*)(frame + 0x230); - case TextFrame: - break; - case TextButtonFrame: - case GlueTextButtonWar3: - frame = *(UINT*)(frame + 0x1e4); - - break; - default: - return 0.f; - } - - return GetCFrameTextHeight(frame); - } - - return 0.f; -} - -void SetFrameFont(UINT frame, LPCSTR filename, float height, UINT flag) { - if (frame) { - switch (GetFrameType(frame)) - { - case MissingFrame: - break; - case EditBox: - SetCEditBoxFont(frame, NULL, filename, height, flag); - - break; - default: - SetCLayerFont(frame, NULL, filename, height, flag); - - break; - } - } -} - -void SetFrameWidth(UINT frame, float width) { - UINT layout = GetFrameLayout(frame); - - if (!layout) { - return; - } - - SetCLayoutFrameWidth(layout, NULL, width); -} - -void SetFrameHeight(UINT frame, float height) { - UINT layout = GetFrameLayout(frame); - - if (!layout) { - return; - } - - SetCLayoutFrameHeight(layout, NULL, height); -} - -void SetFrameSize(UINT frame, float width, float height) { - SetFrameWidth(frame, width); - SetFrameHeight(frame, height); -} - -void SetFrameScale(UINT frame, float scale) { - UINT layout = GetFrameLayout(frame); - - if (!layout) { - return; - } - - SetCLayoutFrameScale(layout, NULL, scale); -} - -void SetFrameAbsolutePoint(UINT frame, EFramePoint point, float offsetX, float offsetY) { - UINT layout = GetFrameLayout(frame); - - if (!layout) { - return; - } - - SetCLayoutFrameAbsolutePoint(layout, NULL, point, offsetX, offsetY, 1); -} - -void SetFramePoint(UINT frame, EFramePoint point, UINT relativeframe, EFramePoint relativepoint, float offsetX, float offsetY) { - UINT layout = GetFrameLayout(frame); - UINT relativelayout = GetFrameLayout(relativeframe); - - if (!layout || !relativelayout) { - return; - } - - SetCLayoutFramePoint(layout, NULL, point, relativelayout, relativepoint, offsetX, offsetY, 1); -} - -float GetFrameWidth(UINT frame) { - UINT layout = GetFrameLayout(frame); - - if (!layout) { - return NULL; - } - - return *(float*)(layout + 0x58); -} - -float GetFrameHeight(UINT frame) { - UINT layout = GetFrameLayout(frame); - - if (!layout) { - return NULL; - } - - return *(float*)(layout + 0x5c); -} - -UINT GetFramePoint(UINT frame, EFramePoint point) { - UINT layout = GetFrameLayout(frame); - - if (!layout) { - return NULL; - } - - return *(UINT*)(layout + 4 * (UINT)point + 8); -} - -UINT GetFramePointParent(UINT frame, EFramePoint point) { - return *(UINT*)(GetFramePoint(frame, point) + 4); -} - -UINT GetFramePointRelativePoint(UINT frame, EFramePoint point) { - return *(UINT*)(GetFramePoint(frame, point) + 8); -} - -float GetFramePointX(UINT frame, EFramePoint point) { - return *(float*)(GetFramePoint(frame, point) + 12); -} - -float GetFramePointY(UINT frame, EFramePoint point) { - return *(float*)(GetFramePoint(frame, point) + 16); -} - -UINT GetTriggerFrame() { - return triggerFrame; -} - -float GetFrameValue(UINT frame) { - switch (GetFrameType(frame)) - { - case Slider: - return *(float*)(frame + 0x1f4); - case SimpleStatusBar: - return *(float*)(frame + 0x130); - case StatusBar: - return *(float*)(frame + 0x1bc); - } - - return 0.f; -} - -float GetTriggerFrameValue() { - if (triggerEvent == FRAMEEVENT_MOUSE_WHEEL) { - return (float)*pWheelState; - } - - return GetFrameValue(triggerFrame); -} - -void SetFrameValue(UINT frame, float value) { - switch (GetFrameType(frame)) - { - case Slider: - SetCSliderCurrentValue(frame, NULL, value, 1); - - break; - case SimpleStatusBar: - SetCSimpleStatusBarValue(frame, NULL, value); - - break; - case StatusBar: - float min = *(float*)(frame + 0x1b4); - // float max = *(float*)(frame + 0x1b8); - - value = value < min ? min : value; - - *(float*)(frame + 0x1bc) = value; - - break; - } -} - -void SetFrameMinMaxValue(UINT frame, float minValue, float maxValue) { - float value = 0.f; - - switch (GetFrameType(frame)) { - case Slider: - value = *(float*)(frame + 0x1f4); - - *(float*)(frame + 0x1ec) = minValue; - *(float*)(frame + 0x1f0) = maxValue; - - value = value >= minValue ? (value <= maxValue ? value : maxValue) : minValue; - - SetCSliderCurrentValue(frame, NULL, value, 1); - - break; - case SimpleStatusBar: - SetCSimpleStatusBarMinMaxValue(frame, NULL, minValue, maxValue); - - break; - case StatusBar: - SetCStatusBarMinMaxValue(frame, NULL, minValue, maxValue); - - break; - } -} - -void SetFrameStepSize(UINT frame, float stepSize) { - if (GetFrameType(frame) == Slider) { - *(float*)(frame + 0x1f8) = stepSize; - } -} - -void SetFrameTexture(UINT frame, LPCSTR texFile, BOOL flag) { - switch (GetFrameType(frame)) - { - case BackdropFrame: - SetCBackDropFrameTexture(frame, NULL, texFile, NULL, flag, NULL, 1); - - break; - case SimpleStatusBar: - SetCSimpleStatusBarTexture(frame, NULL, texFile, flag); - - break; - case SimpleTexture: - SetCSimpleTextureTexture(frame, NULL, texFile, flag); - - break; - } -} - -void SetFrameEnable(UINT frame, BOOL enabled) { - if (frame) { - SetCControlState(frame, NULL, enabled); - } -} - -void ClickFrame(UINT frame) { - if (frame) { - ClickCFrame(frame, NULL, 1); - } -} - -void SetFrameModel(UINT frame, LPCSTR modelFile, UINT modeltype, BOOL flag) { - switch (GetFrameType(frame)) - { - case ModelFrame: - AddCModelFrameModel(frame, NULL, modelFile, modeltype); - - break; - case SpriteFrame: - SetCSpriteFrameArt(frame, NULL, modelFile, modeltype, flag); - - break; - case StatusBar: - SetCStatusBarArt(frame, NULL, modelFile, modeltype); - - break; - } -} - -void DestroyFrame(UINT frame) { - if (frame) { - for (size_t i = 0; i < frames.size(); i++) { - if (frames[i] == frame) { - frames.erase(frames.begin() + i); - } - } - - auto frameevent = frameEventHashTable.find(frame); - if (frameevent != frameEventHashTable.end()) { - //frameevent->second.clear(); - frameEventHashTable.erase(frameevent); - } - - DestroyCFrame(frame, NULL, 1); - } -} - -void SetFrameVisible(UINT frame, BOOL visible) { - if (frame) { - if (visible) { - ShowCFrame(frame); - } - else { - HideCFrame(frame); - } - } -} - -void SetGameUIVisible(BOOL visible) { - CGameUI* gameui = GetGameUI(0, 0); - - if (visible) { - HideCFrame((UINT)gameui->SimpleConsole); - ShowCFrame((UINT)gameui->TimeOfDayIndicator); - ShowCFrame((UINT)gameui->Portrait); - ShowCFrame((UINT)gameui->Minimap); - - SetFramePoint((UINT)gameui->WorldFrameWar3, FRAMEPOINT_TOPRIGHT, (UINT)gameui, FRAMEPOINT_TOPRIGHT, 0.f, -0.02f); - SetFramePoint((UINT)gameui->WorldFrameWar3, FRAMEPOINT_BOTTOMLEFT, (UINT)gameui, FRAMEPOINT_BOTTOMLEFT, 0.f, 0.13f); - } - else { - ShowCFrame((UINT)gameui->SimpleConsole); - HideCFrame((UINT)gameui->TimeOfDayIndicator); - HideCFrame((UINT)gameui->Portrait); - HideCFrame((UINT)gameui->Minimap); - - SetFramePoint((UINT)gameui->WorldFrameWar3, FRAMEPOINT_TOPRIGHT, (UINT)gameui, FRAMEPOINT_TOPRIGHT, 0.f, 0.f); - SetFramePoint((UINT)gameui->WorldFrameWar3, FRAMEPOINT_BOTTOMLEFT, (UINT)gameui, FRAMEPOINT_BOTTOMLEFT, 0.f, 0.f); - } -} - -void SetFrameCheck(UINT frame, BOOL check) { - if (GetFrameType(frame) == GlueCheckBoxWar3) { - *(BOOL*)(frame + 0x1d4) = *(BOOL*)(frame + 0x1d4) ^ (check << 5); - } -} - -//--------------------------------------------------------- - -BOOL __stdcall eventCallback(UINT frame, UINT eventtype, DWORD eventaddress) { - EFrameEvent event = GetFrameEventType(eventtype); - UINT eventData = *(UINT*)(eventaddress + 0x10); - - switch (event) - { - case FRAMEEVENT_MOUSE_MOVE: - event = eventData ? FRAMEEVENT_MOUSE_ENTER : FRAMEEVENT_MOUSE_LEAVE; - - break; - case FRAMEEVENT_CHECKBOX_CHECK: - event = eventData ? FRAMEEVENT_CHECKBOX_CHECKED : FRAMEEVENT_CHECKBOX_UNCHECKED; - - break; - case FRAMEEVENT_EDITBOX_BUTTON_DOWN: - event = (eventData == 0x201) ? FRAMEEVENT_EDITBOX_ENTER : FRAMEEVENT_EDITBOX_TEXT_CHANGED; - - break; - } - - auto frameevent = frameEventHashTable[frame].find(event); - if (frameevent != frameEventHashTable[frame].end()) { - triggerFrame = frame; - triggerEvent = event; - - UINT trigger = frameevent->second; - if (TriggerEvaluate(trigger)) { - TriggerExecute(trigger); - - return TRUE; - } - - return FALSE; - } - - return -1; -} - -void GameUI_reset() { - frameEventHashTable.clear(); - frames.clear(); - triggerFrame = NULL; - triggerEvent = FRAMEEVENT_NONE; -} \ No newline at end of file diff --git a/Src/GameUI.h b/Src/GameUI.h deleted file mode 100644 index f029b90..0000000 --- a/Src/GameUI.h +++ /dev/null @@ -1,507 +0,0 @@ -#pragma once - -#include -#include -#include - -enum EOriginFrame : UINT { - ORIGIN_FRAME_GAME_UI, - ORIGIN_FRAME_WORLD_FRAME, - ORIGIN_FRAME_HERO_BAR, - ORIGIN_FRAME_HERO_BUTTON, - ORIGIN_FRAME_HERO_HP_BAR, - ORIGIN_FRAME_HERO_MANA_BAR, - ORIGIN_FRAME_HERO_BUTTON_INDICATOR, - ORIGIN_FRAME_ITEM_BUTTON, - ORIGIN_FRAME_COMMAND_BUTTON, - ORIGIN_FRAME_SYSTEM_BUTTON, - ORIGIN_FRAME_PORTRAIT, - ORIGIN_FRAME_MINIMAP, - ORIGIN_FRAME_MINIMAP_BUTTON, - ORIGIN_FRAME_TOOLTIP, - ORIGIN_FRAME_UBERTOOLTIP, - ORIGIN_FRAME_CHAT_MSG, - ORIGIN_FRAME_UNIT_MSG, - ORIGIN_FRAME_TOP_MSG -}; - -enum EFramePoint : UINT { - FRAMEPOINT_TOPLEFT, - FRAMEPOINT_TOP, - FRAMEPOINT_TOPRIGHT, - FRAMEPOINT_LEFT, - FRAMEPOINT_CENTER, - FRAMEPOINT_RIGHT, - FRAMEPOINT_BOTTOMLEFT, - FRAMEPOINT_BOTTOM, - FRAMEPOINT_BOTTOMRIGHT -}; - -enum EFrameType : UINT { - MissingFrame, // Frame doesn't exist - BackdropFrame, - ButtonFrame, - ChatMode, - CommandButton, - CursorFrame, - EditBox, - Frame, - FloatingFrame, - GameUI, - HeroBarButton, - HighlightFrame, - LayoutFrame, - MessageFrame, - Minimap, - ModelFrame, - PortraitButton, - ScreenFrame, - SimpleButton, - SimpleFontString, - SimpleFrame, - SimpleGlueFrame, - Uknown_1, - SimpleMessageFrame, - Slider, - SpriteFrame, - StatBar, - TextArea, - TextButtonFrame, - TextFrame, - UberToolTipWar3, - WorldFrameWar3, - GlueButtonWar3, - GlueTextButtonWar3, - GlueCheckBoxWar3, - GluePopupMenuWar3, - GlueEditBoxWar3, - SlashChatBox, - TimerTextFrame, - SimpleStatusBar, - StatusBar, - UpperButtonBar, - ResourceBar, - SimpleConsole, - PeonBar, - HeroBar, - TimeOfDayIndicator, - InfoBar, - TimeCover, - ProgressIndicator, - HeroLevelBar, - BuildTimeIndicator, - InfoPanelDestructableDetail, - InfoPanelItemDetail, - InfoPanelIconAlly, - InfoPanelIconHero, - InfoPanelIconGold, - InfoPanelIconFood, - InfoPanelIconRank, - InfoPanelIconArmor, - InfoPanelIconDamage, - InfoPanelCargoDetail, - InfoPanelBuildingDetail, - InfoPanelUnitDetail, - SimpleTexture -}; - -EFrameType GetFrameType(UINT frame); - -enum EFrameEvent : UINT { - FRAMEEVENT_NONE, - FRAMEEVENT_CONTROL_CLICK, - FRAMEEVENT_MOUSE_MOVE, - FRAMEEVENT_MOUSE_ENTER = 2, - FRAMEEVENT_MOUSE_LEAVE, - FRAMEEVENT_MOUSE_UP, - FRAMEEVENT_MOUSE_DOWN, - FRAMEEVENT_MOUSE_WHEEL, - FRAMEEVENT_CHECKBOX_CHECK, - FRAMEEVENT_CHECKBOX_CHECKED = 7, - FRAMEEVENT_CHECKBOX_UNCHECKED, - FRAMEEVENT_EDITBOX_BUTTON_DOWN, - FRAMEEVENT_EDITBOX_TEXT_CHANGED = 9, - FRAMEEVENT_POPUPMENU_ITEM_CHANGED, - FRAMEEVENT_MOUSE_DOUBLECLICK, - FRAMEEVENT_SPRITE_ANIM_UPDATE, - FRAMEEVENT_SLIDER_VALUE_CHANGED, - FRAMEEVENT_DIALOG_CANCEL, - FRAMEEVENT_DIALOG_ACCEPT, - FRAMEEVENT_EDITBOX_ENTER -}; - -struct CGameUI { - int FrameType; - int field0004; - int field0008; - int field000C; - int field0010; - int field0014; - int field0018; - int field001C; - int field0020; - int field0024; - int field0028; - int field002C; - int field0030; - int field0034; - int field0038; - int field003C; - int field0040; - int field0044; - int field0048; - int field004C; - int field0050; - int field0054; - int field0058; - int field005C; - int field0060; - int field0064; - int field0068; - int field006C; - int field0070; - int field0074; - int field0078; - int field007C; - int field0080; - int field0084; - int field0088; - int field008C; - int field0090; - int field0094; - int field0098; - int field009C; - int field00A0; - int field00A4; - int field00A8; - int field00AC; - int field00B0; - int LayoutType; - int field00B8; - int field00BC; - int field00C0; - int field00C4; - int field00C8; - int field00CC; - int field00D0; - int field00D4; - int field00D8; - int field00DC; - int field00E0; - int field00E4; - int field00E8; - int field00EC; - int field00F0; - int field00F4; - int field00F8; - int field00FC; - int field0100; - int field0104; - int field0108; - int field010C; - int field0110; - int field0114; - int field0118; - int field011C; - int field0120; - int field0124; - int field0128; - int field012C; - int field0130; - int field0134; - int field0138; - int field013C; - int field0140; - int field0144; - int field0148; - int field014C; - int field0150; - int field0154; - int field0158; - int field015C; - int field0160; - int field0164; - int field0168; - int field016C; - int field0170; - int field0174; - int field0178; - int field017C; - int field0180; - int field0184; - int field0188; - int field018C; - int field0190; - int field0194; - int field0198; - int field019C; - int field01A0; - int field01A4; - int field01A8; - int isUserInputEnabled; - int isUserInterfaceEnabled; - int field01B4; - int field01B8; - int field01BC; - int field01C0; - int field01C4; - int field01C8; - int field01CC; - int field01D0; - int field01D4; - int field01D8; - int field01DC; - int field01E0; - int field01E4; - int field01E8; - int field01EC; - int field01F0; - int field01F4; - int field01F8; - int field01FC; - int field0200; - int field0204; - int field0208; - int field020C; - int field0210; - int field0214; - int field0218; - int field021C; - int field0220; - int field0224; - int field0228; - int field022C; - int field0230; - int field0234; - int field0238; - int field023C; - int field0240; - int field0244; - int field0248; - int field024C; - int field0250; - int Camera; - int isInGameMenu; - int field025C; - int isGamePaused; - int field0264; - int field0268; - int field026C; - int field0270; - int field0274; - int field0278; - int field027C; - int field0280; - int field0284; - int field0288; - int field028C; - int isDragSelectionEnabled; - int isDragSelectionVisible; - int isPreSelectionEnabled; - int isPreSelectionVisible; - int isSelectionEnabled; - int isSelectionVisible; - int field02A8; - int field02AC; - int field02B0; - int field02B4; - int field02B8; - int field02BC; - int field02C0; - int field02C4; - int field02C8; - int field02CC; - int field02D0; - int field02D4; - int field02D8; - int field02DC; - int field02E0; - int field02E4; - int field02E8; - int field02EC; - int field02F0; - int field02F4; - int field02F8; - int field02FC; - int field0300; - int field0304; - int field0308; - int field030C; - float MouseWorldX; // Use from WorldFrame - float MouseWorldY; - float MouseWorldZ; - int field031C; - int field0320; - int field0324; - int field0328; - int field032C; - int field0330; - int field0334; - int field0338; - int field033C; - int field0340; - int field0344; - int field0348; - int field034C; - int field0350; - int field0354; - int field0358; - int field035C; - int field0360; - int field0364; - int field0368; - int field036C; - int field0370; - int field0374; - int field0378; - int field037C; - int field0380; - int field0384; - int field0388; - int field038C; - int field0390; - int field0394; - int field0398; - int field039C; - int field03A0; - int field03A4; - int field03A8; - int field03AC; - int field03B0; - int field03B4; - int field03B8; - CGameUI* WorldFrameWar3; // CWorldFrameWar3* - CGameUI* Minimap; // CFrame* - CGameUI* InfoBar; - CGameUI* CommandBar; - CGameUI* ResourceBarFrame; - CGameUI* UpperButtonBarFrame; - int field03D4; - CGameUI* ClickableBlock; - CGameUI* HeroBar; - CGameUI* PeonBar; - CGameUI* Message; // CSimpleMessageFrame* - CGameUI* UnitMessage; // CSimpleMessageFrame* - CGameUI* ChatMessage; // CSimpleMessageFrame* - CGameUI* TopMessage; // CSimpleMessageFrame* - CGameUI* Portrait; // CFrame* - CGameUI* TimeOfDayIndicator; // CFrame* - CGameUI* ChatEditBar; - CGameUI* CinematicPanel; - int field0404; - CGameUI* MinimapButtons[5]; - CGameUI* FrameB; // CFrame* - CGameUI* MouseBorders; - CGameUI* FrameA; // CFrame* - CGameUI* SimpleConsole; - int QuickSaveHotKey; - int QuickLoadHotKey; - int QuickHelpHotKey; - int QuickOptionsHotKey; - int QuickQuitHotKey; - int MinimapSignalHotKey; - int MinimapTerrainHotKey; - int MinimapColorsHotKey; - int MinimapCreepsHotKey; - int FormationToggleHotKey; -}; - -EFrameType GetFrameType(UINT frame); - -UINT GetFrameLayout(UINT frame); - -CGameUI* GetGameUI(UINT unknown1 = NULL, UINT unknown2 = NULL); - -UINT GetOriginFrame(EOriginFrame originframe, UINT index); - -UINT GetPanelButton(UINT frame, BYTE row, BYTE column); - -UINT GetTooltipFrame(UINT unknown0 = NULL); - -BOOL LoadTOCFile(LPCSTR filename); - -UINT GetFrameByName(LPCSTR framename, UINT id); - -UINT GetFrameParent(UINT frame); - -UINT GetFrameChildrenCount(UINT frame); - -UINT GetFrameChild(UINT frame, UINT index); - -void TriggerRegisterFrameEvent(UINT trigger, UINT frame, EFrameEvent event); - -UINT CreateFrame(LPCSTR baseframe, UINT parentframe, EFramePoint point, EFramePoint relativepoint); - -void SetFrameText(UINT frame, LPCSTR text); - -LPCSTR GetFrameText(UINT frame); - -void SetFrameTextColor(UINT frame, BYTE red, BYTE green, BYTE blue, BYTE alpha); - -float GetFrameTextHeight(UINT frame); - -void SetFrameFont(UINT frame, LPCSTR filename, float height, UINT flag); - -void SetFrameWidth(UINT frame, float width); - -void SetFrameHeight(UINT frame, float height); - -void SetFrameSize(UINT frame, float width, float height); - -void SetFrameScale(UINT frame, float scale); - -void SetFrameAbsolutePoint(UINT frame, EFramePoint point, float offsetX, float offsetY); - -void SetFramePoint(UINT frame, EFramePoint point, UINT relativeframe, EFramePoint relativepoint, float offsetX, float offsetY); - -float GetFrameWidth(UINT frame); - -float GetFrameHeight(UINT frame); - -UINT GetFramePointParent(UINT frame, EFramePoint point); - -UINT GetFramePointRelativePoint(UINT frame, EFramePoint point); - -float GetFramePointX(UINT frame, EFramePoint point); - -float GetFramePointY(UINT frame, EFramePoint point); - -UINT GetTriggerFrame(); - -float GetFrameValue(UINT frame); - -float GetTriggerFrameValue(); - -void SetFrameValue(UINT frame, float value); - -void SetFrameMinMaxValue(UINT frame, float minValue, float maxValue); - -void SetFrameStepSize(UINT frame, float stepSize); - -void SetFrameTexture(UINT frame, LPCSTR texFile, BOOL flag); - -void SetFrameEnable(UINT frame, BOOL enabled); - -void ClickFrame(UINT frame); - -void SetFrameModel(UINT frame, LPCSTR modelFile, UINT modeltype, BOOL flag); - -void DestroyFrame(UINT frame); - -void SetFrameVisible(UINT frame, BOOL visible); - -void SetGameUIVisible(BOOL visible); - -void SetFrameCheck(UINT frame, BOOL check); - -//--------------------------------------------------------- - -BOOL __stdcall eventCallback(UINT frame, UINT eventtype, DWORD eventaddress); - -void GameUI_reset(); - -//--------------------------------------------------------- - -extern std::map> frameEventHashTable; - -extern std::vector frames; \ No newline at end of file diff --git a/Src/Hooks.cpp b/Src/Hooks.cpp index 9a96148..c755208 100644 --- a/Src/Hooks.cpp +++ b/Src/Hooks.cpp @@ -1,134 +1,42 @@ +#include "pch.h" #include "Hooks.h" #include "LuaMachine.h" -#include "GameUI.h" -#include "Global.h" -#include -auto jassEntryPointTrue = (BOOL(__fastcall*)(UINT))((UINT_PTR)gameBase + 0x3b54b0); -auto getWarcraftIDTrue = (DWORD(__stdcall*)())((UINT_PTR)gameBase + 0x537ed0); -auto isFrameHasEventObserverTrue = (BOOL(__fastcall*)(UINT, UINT, UINT, UINT))((UINT_PTR)gameBase + 0x62a580); -auto frameEventCallbackTrue = (BOOL(__fastcall*)(UINT, UINT, DWORD))((UINT_PTR)gameBase + 0x629a90); -auto CreateMatrixPerspectiveFovTrue = (void(__fastcall*)(UINT, UINT, float, float, float, float))((UINT_PTR)gameBase + 0x7b66f0); -auto BuildHPBarsTrue = (void(__fastcall*)(UINT, UINT, UINT, UINT))((UINT_PTR)gameBase + 0x379a30); +#define AttachDetour(pointer, detour) (DetourUpdateThread(GetCurrentThread()), DetourAttach(&(PVOID&)pointer, detour)) +#define DetachDetour(pointer, detour) (DetourUpdateThread(GetCurrentThread()), DetourDetach(&(PVOID&)pointer, detour)) -BOOL __fastcall jassEntryPoint(UINT unknown1) { - return jassEntryPointTrue(unknown1) && startLua(); -} +namespace Hooks { + auto SetJassState = (void(__fastcall*)(BOOL jassState))((std::ptrdiff_t)gameBase + 0x2ab0e0); + auto GetWarcraftID = (DWORD(__stdcall*)())((std::ptrdiff_t)gameBase + 0x537ed0); -DWORD __stdcall getWarcraftID() -{ - return *(DWORD*)GAME_ID; -} - -BOOL __fastcall isFrameHasEventObserver(UINT frame, UINT, UINT eventcode) { - if (frameEventHashTable.find(frame) != frameEventHashTable.end()) { - return TRUE; + DWORD GetWarcraftIDCustom() + { + return *(DWORD*)GAME_ID; } - UINT table = *(DWORD*)(frame + 8); + void __fastcall SetJassStateCustom(BOOL jassState) { + if (jassState == TRUE) { + LuaMachine::StartLua(); + } - if (!table) { - return FALSE; + return SetJassState(jassState); } - return reinterpret_cast((UINT_PTR)gameBase + 0x62a1c0)(table, NULL, eventcode, 0); -} - -BOOL __fastcall frameEventCallback(UINT frame, UINT, DWORD eventaddress) { - UINT eventtype = *(UINT*)(eventaddress + 8); - BOOL result = eventCallback(frame, eventtype, eventaddress); + void AttachHooks() { + DetourTransactionBegin(); - return result == -1 ? reinterpret_cast(*(DWORD*)(*(DWORD*)frame + 0x14))(frame, NULL, eventtype, eventaddress) : result; -} + AttachDetour(SetJassState, SetJassStateCustom); + AttachDetour(GetWarcraftID, GetWarcraftIDCustom); -float wideScreenMul = 1.0f; -void __fastcall CreateMatrixPerspectiveFov(UINT outMatrix, UINT unused, float fovY, float aspectRatio, float nearZ, float farZ) { - RECT rect; - if (gameWindow && GetWindowRect(gameWindow, &rect)) { - float width = float(rect.right - rect.left); - float height = 1.0f / (rect.bottom - rect.top); - wideScreenMul = width * height * 0.75f; + DetourTransactionCommit(); } - float yScale = 1.0f / tan(fovY * 0.5f / sqrt(aspectRatio * aspectRatio + 1.0f)); - float xScale = yScale / (aspectRatio * wideScreenMul); - - *(float*)(outMatrix) = xScale; - *(float*)(outMatrix + 16) = 0.0f; - *(float*)(outMatrix + 32) = 0.0f; - *(float*)(outMatrix + 48) = 0.0f; - - *(float*)(outMatrix + 4) = 0.0f; - *(float*)(outMatrix + 20) = yScale; - *(float*)(outMatrix + 36) = 0.0f; - *(float*)(outMatrix + 52) = 0.0f; - - *(float*)(outMatrix + 8) = 0.0f; - *(float*)(outMatrix + 24) = 0.0f; - *(float*)(outMatrix + 40) = (nearZ + farZ) / (farZ - nearZ); - *(float*)(outMatrix + 56) = (-2.0f * nearZ * farZ) / (farZ - nearZ); - - *(float*)(outMatrix + 12) = 0.0f; - *(float*)(outMatrix + 28) = 0.0f; - *(float*)(outMatrix + 44) = 1.0f; - *(float*)(outMatrix + 60) = 0.0f; -} + void DetachHooks() { + DetourTransactionBegin(); -void __fastcall BuildHPBars(UINT a1, UINT unused, UINT a2, UINT a3) { - BuildHPBarsTrue(a1, unused, a2, a3); + DetachDetour(SetJassState, SetJassStateCustom); + DetachDetour(GetWarcraftID, GetWarcraftIDCustom); - UINT_PTR pHPBarFrame = *((UINT_PTR*)a1 + 3); - if (pHPBarFrame) { - *((float*)pHPBarFrame + 22) /= wideScreenMul; + DetourTransactionCommit(); } -} - -//---------------------------------------------------------------- - -void attachHooks() { - DetourTransactionBegin(); - - DetourUpdateThread(GetCurrentThread()); - DetourAttach(&(PVOID&)jassEntryPointTrue, jassEntryPoint); - - DetourUpdateThread(GetCurrentThread()); - DetourAttach(&(PVOID&)getWarcraftIDTrue, getWarcraftID); - - DetourUpdateThread(GetCurrentThread()); - DetourAttach(&(PVOID&)isFrameHasEventObserverTrue, isFrameHasEventObserver); - - DetourUpdateThread(GetCurrentThread()); - DetourAttach(&(PVOID&)frameEventCallbackTrue, frameEventCallback); - - DetourUpdateThread(GetCurrentThread()); - DetourAttach(&(PVOID&)CreateMatrixPerspectiveFovTrue, CreateMatrixPerspectiveFov); - - DetourUpdateThread(GetCurrentThread()); - DetourAttach(&(PVOID&)BuildHPBarsTrue, BuildHPBars); - - DetourTransactionCommit(); -} - -void detachHooks() { - DetourTransactionBegin(); - - DetourUpdateThread(GetCurrentThread()); - DetourDetach(&(PVOID&)jassEntryPointTrue, jassEntryPoint); - - DetourUpdateThread(GetCurrentThread()); - DetourDetach(&(PVOID&)getWarcraftIDTrue, getWarcraftID); - - DetourUpdateThread(GetCurrentThread()); - DetourDetach(&(PVOID&)isFrameHasEventObserverTrue, isFrameHasEventObserver); - - DetourUpdateThread(GetCurrentThread()); - DetourDetach(&(PVOID&)frameEventCallbackTrue, frameEventCallback); - - DetourUpdateThread(GetCurrentThread()); - DetourDetach(&(PVOID&)CreateMatrixPerspectiveFovTrue, CreateMatrixPerspectiveFov); - - DetourUpdateThread(GetCurrentThread()); - DetourDetach(&(PVOID&)BuildHPBarsTrue, BuildHPBars); - - DetourTransactionCommit(); } \ No newline at end of file diff --git a/Src/Hooks.h b/Src/Hooks.h index 296f7d8..6b83c14 100644 --- a/Src/Hooks.h +++ b/Src/Hooks.h @@ -1,7 +1,7 @@ #pragma once -#include +namespace Hooks { + void AttachHooks(); -void attachHooks(); - -void detachHooks(); \ No newline at end of file + void DetachHooks(); +} \ No newline at end of file diff --git a/Src/JassMachine.cpp b/Src/JassMachine.cpp index 07310dc..975c360 100644 --- a/Src/JassMachine.cpp +++ b/Src/JassMachine.cpp @@ -1,34 +1,51 @@ +#include "pch.h" #include "JassMachine.h" #include "LuaMachine.h" -#include "Global.h" +#include "fp_call.h" -PVOID** ppOpcodeList = (PVOID**)((UINT_PTR)gameBase + 0x45ea5a); -BYTE* pOpcodeListSize = (BYTE*)((UINT_PTR)gameBase + 0x45ea4d); -PVOID opcodeDefaultOut = (PVOID)((UINT_PTR)gameBase + 0x45f79a); +namespace JassMachine { + PVOID** ppOpcodeList = (PVOID**)((std::ptrdiff_t)gameBase + 0x45ea5a); + BYTE* pOpcodeListSize = (BYTE*)((std::ptrdiff_t)gameBase + 0x45ea4d); + PVOID opcodeDefaultOutput = (PVOID)((std::ptrdiff_t)gameBase + 0x45f79a); -PVOID OPCODE_FUNCTIONS[44]; + PVOID OPCODE_FUNCTIONS[44]; -DWORD _declspec(naked) opcodeStartLuaThread() { - _asm { - push esi - call startLuaThread + DWORD OpcodeStartLuaThread() { + LuaMachine::StartLuaThread(); - push opcodeDefaultOut - ret + return c_call(JassMachine::opcodeDefaultOutput); } -} -void jassOpcodeInitialize() { - memcpy(OPCODE_FUNCTIONS, *ppOpcodeList, sizeof(OPCODE_FUNCTIONS)); + void JassOpcodeInitialize() { + CopyMemory(OPCODE_FUNCTIONS, *ppOpcodeList, sizeof(OPCODE_FUNCTIONS)); - OPCODE_FUNCTIONS[OPTYPE_STARTLUATHREAD - 2] = opcodeStartLuaThread; // My own opcode function + OPCODE_FUNCTIONS[OPTYPE_STARTLUATHREAD - 2] = OpcodeStartLuaThread; // My own opcode function - DWORD dwOldProtect; - VirtualProtect(pOpcodeListSize, 1, PAGE_EXECUTE_READWRITE, &dwOldProtect); - *pOpcodeListSize = sizeof(OPCODE_FUNCTIONS) / 4 - 1; - VirtualProtect(pOpcodeListSize, 1, dwOldProtect, &dwOldProtect); + DWORD dwOldProtect; + VirtualProtect(pOpcodeListSize, sizeof(BYTE), PAGE_EXECUTE_READWRITE, &dwOldProtect); + *pOpcodeListSize = sizeof(OPCODE_FUNCTIONS) / sizeof(PVOID) - 1; + VirtualProtect(pOpcodeListSize, sizeof(BYTE), dwOldProtect, &dwOldProtect); - VirtualProtect(ppOpcodeList, 4, PAGE_EXECUTE_READWRITE, &dwOldProtect); - *ppOpcodeList = OPCODE_FUNCTIONS; - VirtualProtect(ppOpcodeList, 4, dwOldProtect, &dwOldProtect); + VirtualProtect(ppOpcodeList, sizeof(PVOID), PAGE_EXECUTE_READWRITE, &dwOldProtect); + *ppOpcodeList = OPCODE_FUNCTIONS; + VirtualProtect(ppOpcodeList, sizeof(PVOID), dwOldProtect, &dwOldProtect); + } + + //----------------------------------------------------------- + + PJASS_THREAD_LOCAL GetJassThreadLocal() { + return (PJASS_THREAD_LOCAL)GetInstance(5); + } + + PJASS_INSTANCE GetJassMachine(UINT index) { + std::ptrdiff_t jass_thread = *(std::ptrdiff_t*)(*(UINT*)((std::ptrdiff_t)GetJassThreadLocal() + 0x90) + index * 4); + + return jass_thread ? (PJASS_INSTANCE)jass_thread : NULL; + } + + PJASS_INSTANCE GetJassInstance() { + HANDLE instance = GetJassThreadLocal(); + + return *(std::ptrdiff_t*)((std::ptrdiff_t)instance + 0x14) ? *(PJASS_INSTANCE*)(*(std::ptrdiff_t*)((std::ptrdiff_t)instance + 0xc) + *(UINT*)((std::ptrdiff_t)instance + 0x14) * 4 - 4) : NULL; + } } \ No newline at end of file diff --git a/Src/JassMachine.h b/Src/JassMachine.h index d196d54..6e8fd23 100644 --- a/Src/JassMachine.h +++ b/Src/JassMachine.h @@ -1,142 +1,274 @@ #pragma once -#include -#include #include "Warcraft.h" +#include "JassNatives.h" -enum OPCODES : UINT { - OPTYPE_ENDPROGRAM = 1, - OPTYPE_OLDJUMP, - OPTYPE_FUNCTION, - OPTYPE_ENDFUNCTION, - OPTYPE_LOCAL, - OPTYPE_GLOBAL, - OPTYPE_CONSTANT, - OPTYPE_FUNCARG, - OPTYPE_EXTENDS, - OPTYPE_TYPE, - OPTYPE_POPN, - OPTYPE_MOVRLITERAL, - OPTYPE_MOVRR, - OPTYPE_MOVRV, - OPTYPE_MOVRCODE, - OPTYPE_MOVRA, - OPTYPE_MOVVR, - OPTYPE_MOVAR, - OPTYPE_PUSH, - OPTYPE_POP, - OPTYPE_CALLNATIVE, - OPTYPE_CALLJASS, - OPTYPE_I2R, - OPTYPE_AND, - OPTYPE_OR, - OPTYPE_EQUAL, - OPTYPE_NOTEQUAL, - OPTYPE_LESSEREQUAL, - OPTYPE_GREATEREQUAL, - OPTYPE_LESSER, - OPTYPE_GREATER, - OPTYPE_ADD, - OPTYPE_SUB, - OPTYPE_MUL, - OPTYPE_DIV, - OPTYPE_MOD, - OPTYPE_NEGATE, - OPTYPE_NOT, - OPTYPE_RETURN, - OPTYPE_LABE, - OPTYPE_JUMPIFTRUE, - OPTYPE_JUMPIFFALSE, - OPTYPE_JUMP, - OPTYPE_STARTLUATHREAD -}; - -enum OPCODE_VARIABLE_TYPE : UINT { - OPCODE_VARIABLE_NOTHING = 0, - OPCODE_VARIABLE_UNKNOWN, - OPCODE_VARIABLE_NULL, - OPCODE_VARIABLE_CODE, - OPCODE_VARIABLE_INTEGER, - OPCODE_VARIABLE_REAL, - OPCODE_VARIABLE_STRING, - OPCODE_VARIABLE_HANDLE, - OPCODE_VARIABLE_BOOLEAN, - OPCODE_VARIABLE_INTEGER_ARRAY, - OPCODE_VARIABLE_REAL_ARRAY, - OPCODE_VARIABLE_STRING_ARRAY, - OPCODE_VARIABLE_HANDLE_ARRAY, - OPCODE_VARIABLE_BOOLEAN_ARRAY -}; - -#ifndef _JassMachine_h -#define _JassMachine_h -typedef struct { - DWORD unk; - DWORD zero1; - DWORD zero2; - DWORD zero3; - DWORD zero4; - DWORD zero5; - DWORD type1; - DWORD type2; - DWORD value; - DWORD zero6; - - void set(DWORD value, OPCODE_VARIABLE_TYPE type) { - this->value = value; - type1 = type; - type2 = type; - } - -} JASS_DATA_SLOT, * PJASS_DATA_SLOT; - -typedef struct { -private: - DWORD unk1; - DWORD unk2; - size_t stack_top; // Idk why it's here - PJASS_DATA_SLOT stack[32]; - size_t size; -public: - PJASS_DATA_SLOT pop() { - return stack[--size]; - } - - PJASS_DATA_SLOT& operator[](size_t index) { - return stack[index]; - } - - void clear(size_t number) { - size = number < size ? size - number : 0; - } - - size_t Size() { - return size; - } -} JASS_STACK, * PJASS_STACK; - -typedef struct { -private: - std::vector oplist; -public: - void addop(BYTE opcode, BYTE reg = 0, DWORD value = NULL, BYTE type = OPCODE_VARIABLE_NOTHING, BYTE rettype = OPCODE_VARIABLE_NOTHING) { - JASS_OPCODE* _opcode = new JASS_OPCODE; - _opcode->rettype = rettype; - _opcode->type = type; - _opcode->reg = reg; - _opcode->opcode = opcode; - _opcode->value = value; - - oplist.push_back(*_opcode); - } - - DWORD getcode() { - return ((DWORD)&oplist - (DWORD)getJassMachine()->code_table->codes) / 4; - } - -} JASS_OPLIST, * PJASS_OPLIST; -#endif - -//--------------------------------------------------------- - -void jassOpcodeInitialize(); \ No newline at end of file +namespace JassMachine { + enum OPCODES : BYTE { + OPTYPE_ENDPROGRAM = 1, + OPTYPE_OLDJUMP, + OPTYPE_FUNCTION, + OPTYPE_ENDFUNCTION, + OPTYPE_LOCAL, + OPTYPE_GLOBAL, + OPTYPE_CONSTANT, + OPTYPE_FUNCARG, + OPTYPE_EXTENDS, + OPTYPE_TYPE, + OPTYPE_POPN, + OPTYPE_MOVRLITERAL, + OPTYPE_MOVRR, + OPTYPE_MOVRV, + OPTYPE_MOVRCODE, + OPTYPE_MOVRA, + OPTYPE_MOVVR, + OPTYPE_MOVAR, + OPTYPE_PUSH, + OPTYPE_POP, + OPTYPE_CALLNATIVE, + OPTYPE_CALLJASS, + OPTYPE_I2R, + OPTYPE_AND, + OPTYPE_OR, + OPTYPE_EQUAL, + OPTYPE_NOTEQUAL, + OPTYPE_LESSEREQUAL, + OPTYPE_GREATEREQUAL, + OPTYPE_LESSER, + OPTYPE_GREATER, + OPTYPE_ADD, + OPTYPE_SUB, + OPTYPE_MUL, + OPTYPE_DIV, + OPTYPE_MOD, + OPTYPE_NEGATE, + OPTYPE_NOT, + OPTYPE_RETURN, + OPTYPE_LABE, + OPTYPE_JUMPIFTRUE, + OPTYPE_JUMPIFFALSE, + OPTYPE_JUMP, + OPTYPE_STARTLUATHREAD + }; + + enum OPCODE_VARIABLE_TYPE : BYTE { + OPCODE_VARIABLE_NOTHING = 0, + OPCODE_VARIABLE_UNKNOWN, + OPCODE_VARIABLE_NULL, + OPCODE_VARIABLE_CODE, + OPCODE_VARIABLE_INTEGER, + OPCODE_VARIABLE_REAL, + OPCODE_VARIABLE_STRING, + OPCODE_VARIABLE_HANDLE, + OPCODE_VARIABLE_BOOLEAN, + OPCODE_VARIABLE_INTEGER_ARRAY, + OPCODE_VARIABLE_REAL_ARRAY, + OPCODE_VARIABLE_STRING_ARRAY, + OPCODE_VARIABLE_HANDLE_ARRAY, + OPCODE_VARIABLE_BOOLEAN_ARRAY + }; + + typedef struct { + DWORD unk; + DWORD zero1; + DWORD zero2; + DWORD zero3; + DWORD zero4; + DWORD zero5; + DWORD type1; + DWORD type2; + DWORD value; + DWORD zero6; + + void Set(DWORD value, OPCODE_VARIABLE_TYPE type) { + this->value = value; + type1 = type; + type2 = type; + } + + } JASS_DATA_SLOT, * PJASS_DATA_SLOT; + + typedef struct { + private: + DWORD unk1; + DWORD unk2; + size_t stack_top; // Idk why it's here + PJASS_DATA_SLOT stack[32]; + size_t size; + public: + PJASS_DATA_SLOT Pop() { + return stack[--size]; + } + + PJASS_DATA_SLOT& operator[](size_t index) { + return stack[index]; + } + + void Clear(size_t number) { + size = number < size ? size - number : 0; + } + + size_t Size() { + return size; + } + } JASS_STACK, * PJASS_STACK; + + typedef struct CStringRep { + uintptr_t vtable; // 0x0 + uint32_t refCount; // 0x4 + uint32_t hash; // 0x8 + PVOID table; // 0xC + CStringRep* prev; // 0x10 + /* txtnode */ + void* prevtxtnode; // 0x14 ? + CStringRep* next; // 0x18 + char* text; // 0x1C + } * PCStringRep;//sizeof = 0x20 + + typedef struct { + uintptr_t vtable; // 0x0 void** + uint32_t unk1; // 0x4 + PCStringRep stringRep; // 0x8 + uint32_t unk2; + } RCString, * PRCString; + + typedef struct { + DWORD unk; + size_t size; + PRCString strings; + + /*DWORD Get(UINT index) { + DWORD result = 0; + + if (index < size) { + result = (DWORD)strings + 0x10 * index; + ++* (DWORD*)(result + 0xC); + } + + return result; + }*/ + RCString& GetRCString(size_t index) { + return strings[index]; + } + + CStringRep& GetCStringRep(size_t index) { + return *(strings[index].stringRep); + } + + LPCSTR GetString(size_t index, bool countRef = true) { + if (countRef) { + strings[index].stringRep->refCount++; + } + + return strings[index].stringRep->text; + } + + } STRING_TABLE, * PSTRING_TABLE; + + typedef struct { + BYTE unk[4]; + size_t counter; + DWORD* codes; // max_size = 1024 + + size_t PushCode(DWORD address) { + codes[counter] = address; + + return counter++; + } + + size_t Size() { + return counter; + } + } CODE_TABLE, * PCODE_TABLE; + + typedef struct { + BYTE returntype; + BYTE type; + BYTE reg; + BYTE opcode; + DWORD value; + } JASS_OPCODE, * PJASS_OPCODE; + + typedef struct { + BYTE unk0[0x20]; // 0x00 + PJASS_OPCODE opcode; // 0x20 + BYTE unk1[0x10]; // 0x24 + UINT has_sleep; // 0x34 + BYTE unk2[0x18]; // 0x38 + JASS_DATA_SLOT condition_return_value; // 0x50 + BYTE unk3[0x27D8]; // 0x54 + size_t index; // 0x2850 + BYTE unk4[0x14]; // 0x2854 + PJASS_STACK stack; // 0x2868 + BYTE unk5[0x8]; + PSTRING_TABLE string_table; // 0x2874 + BYTE unk6[0x10]; + PCODE_TABLE code_table; + BYTE unk7[0x1C]; + } JASS_INSTANCE, * PJASS_INSTANCE; + +#pragma pack(push) +#pragma pack(4) + struct JASS_NATIVE { + uintptr_t vTable; // 0x0 + uintptr_t unk1; // 0x04 + uintptr_t unk2; // 0x08 + uintptr_t unk3; // 0x0c + uintptr_t unk4; // 0x10 + JASS_NATIVE* next; // 0x14 + LPCSTR name; // 0x18 + LPVOID callback; // 0x1c + size_t argCount; // 0x20 + LPCSTR arguments; // 0x24 + size_t maxArgs; // 0x28 + size_t minArgs; // 0x2c + uintptr_t unk5; // 0x30 + uintptr_t unk6; // 0x34 + OPCODE_VARIABLE_TYPE returnType; // 0x38 + }; +#pragma pack(pop) + + typedef struct { + uintptr_t vTable; // 0x00 + uintptr_t unk1; // 0x04 + uintptr_t unk2; // 0x08 + uintptr_t unk3; // 0x0c + uintptr_t unk4; // 0x10 + uintptr_t unk5; // 0x14 + uintptr_t unk6; // 0x18 + uintptr_t unk7; // 0x1c + JASS_NATIVE* lastNative; // 0x20 + JASS_NATIVE* firstNative; // 0x24 + } JASS_THREAD_LOCAL, * PJASS_THREAD_LOCAL; + + PJASS_THREAD_LOCAL GetJassThreadLocal(); + + PJASS_INSTANCE GetJassMachine(UINT index = 1); + + PJASS_INSTANCE GetJassInstance(); + + typedef struct { + private: + std::vector oplist; + public: + void AddOperation(OPCODES opcode, BYTE reg = 0, DWORD value = NULL, OPCODE_VARIABLE_TYPE type = OPCODE_VARIABLE_NOTHING, OPCODE_VARIABLE_TYPE returntype = OPCODE_VARIABLE_NOTHING) { + JASS_OPCODE* _opcode = new JASS_OPCODE; + _opcode->returntype = returntype; + _opcode->type = type; + _opcode->reg = reg; + _opcode->opcode = opcode; + _opcode->value = value; + + oplist.push_back(*_opcode); + } + + DWORD GetCode() { + return ((DWORD)&oplist - (DWORD)GetJassMachine()->code_table->codes) / sizeof(DWORD); + } + + } JASS_OPLIST, * PJASS_OPLIST; + + //--------------------------------------------------------- + + void JassOpcodeInitialize(); +} \ No newline at end of file diff --git a/Src/JassNatives.cpp b/Src/JassNatives.cpp index 6fa2959..306218e 100644 --- a/Src/JassNatives.cpp +++ b/Src/JassNatives.cpp @@ -1,166 +1,146 @@ +#include "pch.h" #include "JassNatives.h" -#include "JassMachine.h" #include "LuaMachine.h" -#include "Global.h" - -std::unordered_map jassnatives; -std::unordered_map triggers; - -#pragma pack(push) -#pragma pack(1) -struct asm_opcode_5 { - BYTE opcode; - DWORD value; -}; -#pragma pack(pop) - -struct asm_register_native_function { -private: - asm_opcode_5 push; - asm_opcode_5 mov_edx; - asm_opcode_5 mov_ecx; - asm_opcode_5 call; -public: - bool verify() { - return ((push.opcode == 0x68) && (mov_edx.opcode == 0xBA) && (mov_ecx.opcode == 0xB9) && (call.opcode == 0xE8)); - } - - PCSTR get_params() { - return (PCSTR)(push.value); - } +#include "JassMachine.h" - PCSTR get_name() { - return (PCSTR)(mov_edx.value); - } +namespace Jass { + std::unordered_map jassnatives; + std::unordered_map jassopcodes; - PVOID get_address() { - return (PVOID)(mov_ecx.value); - } -}; + //--------------------------------------------------------- -UINT GetGroupByHandle(UINT handle) { - return ((UINT(__fastcall*)(UINT))((UINT_PTR)gameBase + 0x3bea30))(handle); -} + UINT ToCode(lua_State* l, int index) { + DWORD key = (DWORD)lua_topointer(l, index); + + auto it = jassopcodes.find(key); -UINT GetTriggerByHandle(UINT handle) { - return ((UINT(__fastcall*)(UINT))((UINT_PTR)gameBase + 0x3bdef0))(handle); -} + if (it != jassopcodes.end()) { + return it->second.GetCode(); + } -UINT GetTimerByHandle(UINT handle) { - return ((UINT(__fastcall*)(UINT))((UINT_PTR)gameBase + 0x3bd710))(handle); -} + JassMachine::JASS_OPLIST& oplist = jassopcodes[key]; -//--------------------------------------------------------- + BYTE reg = 0xD8; + oplist.AddOperation(JassMachine::OPTYPE_MOVRLITERAL, reg, LuaMachine::PushFunctionRef(l, index), JassMachine::OPCODE_VARIABLE_INTEGER); + oplist.AddOperation(JassMachine::OPTYPE_PUSH, reg); + oplist.AddOperation(JassMachine::OPTYPE_STARTLUATHREAD); + oplist.AddOperation(JassMachine::OPTYPE_MOVRR); + oplist.AddOperation(JassMachine::OPTYPE_RETURN); -UINT to_code(lua_State* l, int index, UINT objectHandle) { - DWORD key = (DWORD)lua_topointer(l, index); + return oplist.GetCode(); + } - auto it = triggers.find(key); + //--------------------------------------------------------- - if (it != triggers.end()) { - return it->second.getcode(); - } + JASSNATIVE::JASSNATIVE(LPVOID address, std::string params) : m_address(address) { + for (size_t i = 1; i < params.size(); i++) { + if (params[i] == ')') { + break; + } - JASS_OPLIST& oplist = triggers[key]; + size_t beg = i++; + for (; i < params.size() && !isupper(params[i]) && params[i] != ')'; i++); - BYTE reg = 0xD8; - oplist.addop(OPTYPE_MOVRLITERAL, reg, objectHandle, OPCODE_VARIABLE_INTEGER); - oplist.addop(OPTYPE_PUSH, reg); - oplist.addop(OPTYPE_MOVRLITERAL, reg, pushFunctionRef(l, index), OPCODE_VARIABLE_INTEGER); - oplist.addop(OPTYPE_PUSH, reg); - oplist.addop(OPTYPE_MOVRLITERAL, reg, (DWORD)l, OPCODE_VARIABLE_INTEGER); - oplist.addop(OPTYPE_PUSH, reg); - oplist.addop(OPTYPE_STARTLUATHREAD); - oplist.addop(OPTYPE_MOVRR); - oplist.addop(OPTYPE_RETURN); + std::string type = params.substr(beg, i-- - beg); + if (type[0] == 'H') { + type = type.substr(1, type.size() - 2); - return oplist.getcode(); -} + LuaMachine::handlemetatypes[type] = true; + } -//--------------------------------------------------------- + m_params.push_back(type); + } -JASSNATIVE::JASSNATIVE(LPVOID address, LPCSTR params) : _address(address) { - LPCSTR it = params++; + if (size_t beg = params.find(')') + 1) { + std::string type = params.substr(beg); + if (type[0] == 'H') { + type = type.substr(1, type.size() - 2); - for (; *it; it++) { - if (*it != ')') { - if (isupper(*it)) { - _params.push_back((JASS_TYPE)*it); + LuaMachine::handlemetatypes[type] = true; } - } - else { - break; + + m_returntype = type; } } - _rettype = (JASS_TYPE)*(++it); -} + JASSNATIVE::JASSNATIVE() : m_address(NULL) {} -JASSNATIVE::JASSNATIVE() : _address(NULL), _rettype(TYPE_NONE) {} + bool JASSNATIVE::IsValid() { + return m_address && !m_returntype.empty(); + } -bool JASSNATIVE::is_valid() { - return _rettype != TYPE_NONE; -} + const std::vector& JASSNATIVE::GetParams() { + return m_params; + } -const std::vector& JASSNATIVE::get_params() { - return _params; -} + const std::string& JASSNATIVE::GetReturnType() { + return m_returntype; + } -const JASS_TYPE& JASSNATIVE::get_rettype() { - return _rettype; -} + PVOID JASSNATIVE::GetAddress() { + return m_address; + } -PVOID JASSNATIVE::get_address() { - return _address; -} + DWORD JASSNATIVE::Invoke(LPVOID params, size_t size) { + if (!params && size) { + return NULL; + } -BOOL JASSNATIVE::call(LPVOID params, size_t size) { - PVOID function_address = _address; - size_t params_size = size * sizeof UINT; - LPVOID esp_ptr; + PVOID function_address = m_address; + size_t params_size = size * sizeof UINT; + LPVOID esp_ptr; - BOOL result; + DWORD result; - _asm { - sub esp, params_size - mov esp_ptr, esp - } + _asm { + sub esp, params_size + mov esp_ptr, esp + } - memcpy(esp_ptr, params, params_size); + if (size) { + CopyMemory(esp_ptr, params, params_size); + } - _asm { - call [function_address] - mov result, eax + _asm { + call [function_address] + mov result, eax - mov esp, esp_ptr - add esp, params_size + mov esp, esp_ptr + add esp, params_size + } + + return result; } - return result; -} + //--------------------------------------------------------- -//--------------------------------------------------------- + JASSNATIVE& GetNative(std::string name) { + for (auto& native : jassnatives) { + if (native.first == name) { + return native.second; + } + } -JASSNATIVE invalid; + JASSNATIVE nothing; -JASSNATIVE& get_native(LPCSTR name) { - for (auto& native : jassnatives) { - if (!strcmp(native.first, name)) { - return native.second; - } + return nothing; } - return invalid; -} + void JassNativesParse() { + size_t size = 0; + JassMachine::PJASS_THREAD_LOCAL jassThreadLocal = JassMachine::GetJassThreadLocal(); + for (auto native = jassThreadLocal->firstNative; native < jassThreadLocal->lastNative; native = native->next) { + //printf("%s %s = %d\n", native->name, native->arguments, ++size); + jassnatives[native->name] = JASSNATIVE(native->callback, native->arguments); + } -auto jassNativesList = (asm_register_native_function*)((UINT_PTR)gameBase + 0x3d4025); + } -void jassNativesParse() { - for (asm_register_native_function* ptr = jassNativesList; ptr->verify(); ptr++) { - jassnatives[ptr->get_name()] = JASSNATIVE(ptr->get_address(), ptr->get_params()); + void JassNativesReset() { + std::unordered_map().swap(jassnatives); } -} -void JassNatives_reset() { - triggers.clear(); + void JassOpcodesReset() { + jassopcodes.clear(); + } } \ No newline at end of file diff --git a/Src/JassNatives.h b/Src/JassNatives.h index ea530fc..ecdae18 100644 --- a/Src/JassNatives.h +++ b/Src/JassNatives.h @@ -1,94 +1,85 @@ #pragma once -#include -#include -#include -#include -#include -#include "JassMachine.h" - -enum JASS_TYPE : BYTE { - TYPE_NONE = 0, - TYPE_BOOLEAN = 'B', - TYPE_CODE = 'C', - TYPE_HANDLE = 'H', - TYPE_INTEGER = 'I', - TYPE_REAL = 'R', - TYPE_STRING = 'S', - TYPE_NOTHING = 'V', -}; - -inline UINT to_real(float value) { - return *(UINT*)&value; -} - -inline float from_real(UINT value) { - return *(float*)&value; -} - -inline UINT to_string(LPCSTR string) { - UINT* pString = new UINT[8]; - - pString[2] = (UINT)&pString[0]; - pString[7] = (UINT)&string[0]; - - return (UINT)pString; -} - -inline PCSTR from_string(UINT string) { - if (!string) { - return NULL; +//enum JASS_TYPE : BYTE { +// TYPE_NONE = 0, +// TYPE_BOOLEAN = 'B', +// TYPE_CODE = 'C', +// TYPE_HANDLE = 'H', +// TYPE_INTEGER = 'I', +// TYPE_REAL = 'R', +// TYPE_STRING = 'S', +// TYPE_NOTHING = 'V', +//}; + +namespace Jass { + inline UINT ToReal(float value) { + return *(UINT*)&value; } - string = ((UINT*)string)[2]; + inline float FromReal(UINT value) { + return *(float*)&value; + } + + inline UINT ToString(LPCSTR string) { + return this_call((std::ptrdiff_t)gameBase + 0x3baa20, string); + //return std_call((std::ptrdiff_t)gameBase + 0x454930, string, 0); + /* + UINT* pString = new UINT[8]; + + pString[2] = (UINT)&pString[0]; + pString[7] = (UINT)&string[0]; - if (!string) { - return NULL; + return (UINT)pString;*/ } - return (PCSTR)((UINT*)string)[7]; -} + inline PCSTR FromString(UINT string) { + if (!string) { + return NULL; + } -UINT GetGroupByHandle(UINT handle); -UINT GetTriggerByHandle(UINT handle); -UINT GetTimerByHandle(UINT handle); + string = ((UINT*)string)[2]; -UINT to_code(lua_State* l, int index, UINT objectHandle); + if (!string) { + return NULL; + } -inline DWORD to_ID(LPCSTR lpID) { - return (lpID[0] << 24) + (lpID[1] << 16) + (lpID[2] << 8) + lpID[3]; -} + return (PCSTR)((UINT*)string)[7]; + } + + UINT ToCode(lua_State* l, int index); -//--------------------------------------------------------- + inline DWORD ToID(LPCSTR lpID) { + return (lpID[0] << 24) + (lpID[1] << 16) + (lpID[2] << 8) + lpID[3]; + } -#ifndef _JassNatives_h -#define _JassNatives_h -class JASSNATIVE { -public: - JASSNATIVE(LPVOID address, LPCSTR params); - JASSNATIVE(); + //--------------------------------------------------------- - bool is_valid(); - const std::vector& get_params(); - const JASS_TYPE& get_rettype(); - PVOID get_address(); + class JASSNATIVE { + public: + JASSNATIVE(LPVOID address, std::string params); + JASSNATIVE(); - BOOL call(LPVOID params, size_t size); -private: - PVOID _address; - std::vector _params; - JASS_TYPE _rettype; -}; -#endif + bool IsValid(); + const std::vector& GetParams(); + const std::string& GetReturnType(); + PVOID GetAddress(); -//--------------------------------------------------------- + DWORD Invoke(LPVOID params, size_t size); + private: + PVOID m_address; + std::vector m_params; + std::string m_returntype; + }; -JASSNATIVE& get_native(LPCSTR name); + //--------------------------------------------------------- -void jassNativesParse(); + JASSNATIVE& GetNative(std::string name); -void JassNatives_reset(); + void JassNativesParse(); + void JassNativesReset(); + void JassOpcodesReset(); -//--------------------------------------------------------- + //--------------------------------------------------------- -extern std::unordered_map jassnatives; \ No newline at end of file + extern std::unordered_map jassnatives; +} \ No newline at end of file diff --git a/Src/Logger.cpp b/Src/Logger.cpp new file mode 100644 index 0000000..5a8ea41 --- /dev/null +++ b/Src/Logger.cpp @@ -0,0 +1,117 @@ +#include "pch.h" +#include "Logger.h" + +namespace Logger { + void OpenConsole(std::string name) { + AllocConsole(); + freopen_s((FILE**)stdin, "CONIN$", "r", stdin); + freopen_s((FILE**)stdout, "CONOUT$", "w", stdout); + freopen_s((FILE**)stderr, "CONOUT$", "w", stderr); + + SetConsoleCP(65001); + SetConsoleOutputCP(65001); + + if (!name.empty()) { + SetConsoleTitle(name.c_str()); + } + } + + void CloseConsole() { + fclose(stdin); + fclose(stdout); + fclose(stderr); + FreeConsole(); + } + + void ClearConsole() { + /*fflush(stdout); + fflush(stderr);*/ + + HANDLE hStdOut; + CONSOLE_SCREEN_BUFFER_INFO csbi; + DWORD count; + DWORD cellCount; + COORD homeCoords = { 0, 0 }; + + hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); + + if (hStdOut == INVALID_HANDLE_VALUE) { + return; + } + + if (!GetConsoleScreenBufferInfo(hStdOut, &csbi)) { + return; + } + + cellCount = csbi.dwSize.X * csbi.dwSize.Y; + + if (!FillConsoleOutputCharacter(hStdOut, ' ', cellCount, homeCoords, &count)) { + return; + } + + if (!FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, cellCount, homeCoords, &count)) { + return; + } + + SetConsoleCursorPosition(hStdOut, homeCoords); + } + + void Log(LOG_LEVEL level, std::string format, ...) { + char buffer[8192] = { 0 }; + + va_list args; + va_start(args, format); + vsprintf_s(buffer, format.c_str(), args); + va_end(args); + + HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); + WORD color = NULL; + LPCSTR text = NULL; + + switch (level) + { + case LOG_INFO: + color |= FOREGROUND_GREEN; + text = "Info"; + + break; + case LOG_ERROR: + color |= FOREGROUND_RED; + text = "Error"; + + break; + case LOG_DEBUG: + color |= FOREGROUND_BLUE; + text = "Debug"; + + break; + case LOG_WARNING: + color |= FOREGROUND_RED | FOREGROUND_GREEN; + text = "Warning"; + + break; + } + + if (text) { + std::cout << "["; + SetConsoleTextAttribute(console, color); + std::cout << text; + SetConsoleTextAttribute(console, 15); + std::cout << "] "; + } + + std::cout << buffer << std::endl; + } + + std::string format(std::string format, ...) { + va_list args; + va_start(args, format); + + char buffer[8192]; + vsprintf_s(buffer, format.c_str(), args); + + va_end(args); + + return std::string(buffer); + } +} \ No newline at end of file diff --git a/Src/Logger.h b/Src/Logger.h new file mode 100644 index 0000000..d79b5ba --- /dev/null +++ b/Src/Logger.h @@ -0,0 +1,27 @@ +#pragma once + +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x) +#define LINE_STRING TOSTRING(__LINE__) + +#define DEBUG_INFO "[" __FILE__ ":" LINE_STRING "]" + +namespace Logger { + enum LOG_LEVEL { + LOG_NONE, + LOG_INFO, + LOG_ERROR, + LOG_DEBUG, + LOG_WARNING + }; + + void OpenConsole(std::string name = ""); + + void CloseConsole(); + + void ClearConsole(); + + void Log(LOG_LEVEL level, std::string format, ...); + + std::string format(std::string format, ...); +} \ No newline at end of file diff --git a/Src/LuaFunctions.cpp b/Src/LuaFunctions.cpp index 3d2bb9d..8f2b807 100644 --- a/Src/LuaFunctions.cpp +++ b/Src/LuaFunctions.cpp @@ -1,1093 +1,399 @@ +#include "pch.h" #include "LuaFunctions.h" #include "JassNatives.h" -#include "GameUI.h" -#include "MemHack.h" -#include "Warcraft.h" -#include "Utils.h" +#include "LuaMachine.h" +#include "JassMachine.h" +#include "Logger.h" #define lua_registerJassNative(L, n, f) (lua_pushstring(L, (n)), lua_pushcclosure(L, (f), 1), lua_setglobal(L, (n))) -#define lua_registerex(L, n, c, f) (lua_pushstring(L, (n)), lua_pushinteger(L, (c)), lua_pushcclosure(L, (f), 2), lua_setglobal(L, (n))) -#define lua_setint(L, n, v) (lua_pushinteger(L, v), lua_setglobal(L, n)) -BOOL checkParams(lua_State* l) { - LPCSTR name = lua_tostring(l, lua_upvalueindex(1)); - int size = (int)lua_tointeger(l, lua_upvalueindex(2)); +std::map destroyers = { + {"DestroyTimer", true}, + {"DestroyGroup", true}, + {"DestroyForce", true}, + {"DestroyTrigger", true}, + {"DestroyCondition", true}, + {"DestroyFiler", true}, + {"DestroyBoolExpr", true}, + {"DestroyFogModifier", true}, + {"DialogDestroy", true}, + {"DestroyUnitPool", true}, + {"DestroyItemPool", true}, + {"DestroyTextTag", true}, + {"DestroyQuest", true}, + {"DestroyDefeatCondition", true}, + {"DestroyTimerDialog", true}, + {"DestroyLeaderboard", true}, + {"DestroyMultiboard", true}, + {"DestroyEffect", true}, + {"DestroyLightning", true}, + {"DestroyImage", true}, + {"DestroyUbersplat", true}, + + {"RemoveRect", true}, + {"RemoveRegion", true}, + {"RemoveLocation", true}, + {"RemoveDestructable", true}, + {"RemoveItem", true}, + {"RemoveUnit", true}, + {"RemoveWeatherEffect", true} +}; + +std::map inheritance = { + { "agent" , "handle" }, + { "event" , "agent" }, + { "player" , "agent" }, + { "widget" , "agent" }, + { "unit" , "widget" }, + { "destructable" , "widget" }, + { "item" , "widget" }, + { "ability" , "agent" }, + { "buff" , "ability" }, + { "force" , "agent" }, + { "group" , "agent" }, + { "trigger" , "agent" }, + { "triggercondition" , "agent" }, + { "triggeraction" , "handle" }, + { "timer" , "agent" }, + { "location" , "agent" }, + { "region" , "agent" }, + { "rect" , "agent" }, + { "boolexpr" , "agent" }, + { "sound" , "agent" }, + { "conditionfunc" , "boolexpr" }, + { "filterfunc" , "boolexpr" }, + { "unitpool" , "handle" }, + { "itempool" , "handle" }, + { "race" , "handle" }, + { "alliancetype" , "handle" }, + { "racepreference" , "handle" }, + { "gamestate" , "handle" }, + { "igamestate" , "gamestate" }, + { "fgamestate" , "gamestate" }, + { "playerstate" , "handle" }, + { "playerscore" , "handle" }, + { "playergameresult" , "handle" }, + { "unitstate" , "handle" }, + { "aidifficulty" , "handle" }, + { "eventid" , "handle" }, + { "gameevent" , "eventid" }, + { "playerevent" , "eventid" }, + { "playerunitevent" , "eventid" }, + { "unitevent" , "eventid" }, + { "limitop" , "eventid" }, + { "widgetevent" , "eventid" }, + { "dialogevent" , "eventid" }, + { "unittype" , "handle" }, + { "gamespeed" , "handle" }, + { "gamedifficulty" , "handle" }, + { "gametype" , "handle" }, + { "mapflag" , "handle" }, + { "mapvisibility" , "handle" }, + { "mapsetting" , "handle" }, + { "mapdensity" , "handle" }, + { "mapcontrol" , "handle" }, + { "playerslotstate" , "handle" }, + { "volumegroup" , "handle" }, + { "camerafield" , "handle" }, + { "camerasetup" , "handle" }, + { "playercolor" , "handle" }, + { "placement" , "handle" }, + { "startlocprio" , "handle" }, + { "raritycontrol" , "handle" }, + { "blendmode" , "handle" }, + { "texmapflags" , "handle" }, + { "effect" , "agent" }, + { "effecttype" , "handle" }, + { "weathereffect" , "handle" }, + { "terraindeformation" , "handle" }, + { "fogstate" , "handle" }, + { "fogmodifier" , "agent" }, + { "dialog" , "agent" }, + { "button" , "agent" }, + { "quest" , "agent" }, + { "questitem" , "agent" }, + { "defeatcondition" , "agent" }, + { "timerdialog" , "agent" }, + { "leaderboard" , "agent" }, + { "multiboard" , "agent" }, + { "multiboarditem" , "agent" }, + { "trackable" , "agent" }, + { "gamecache" , "agent" }, + { "version" , "handle" }, + { "itemtype" , "handle" }, + { "texttag" , "handle" }, + { "attacktype" , "handle" }, + { "damagetype" , "handle" }, + { "weapontype" , "handle" }, + { "soundtype" , "handle" }, + { "lightning" , "handle" }, + { "pathingtype" , "handle" }, + { "image" , "handle" }, + { "ubersplat" , "handle" }, + { "hashtable" , "agent" } +}; + +namespace LuaFunctions { + bool IsChild(const std::string& maintype, std::string childtype) { + do { + if (maintype == childtype) { + return true; + } - if (size > lua_gettop(l)) { - return luaL_error(l, "function '%s' must have %d %s", name, size, size > 1 ? "arguments" : "argument"); - } + childtype = inheritance[childtype]; + } while (!childtype.empty()); - for (int i = 1; i <= size; i++) { - if (lua_isnil(l, i)) { - return luaL_error(l, "Argument number %d of function '%s' mustn't be equal to nil", i, name); - } + return false; } - return FALSE; -} - -//-------------------------------------------------------- -// JassNatives - -int lua_callNative(lua_State* l) { - std::string name = lua_tostring(l, lua_upvalueindex(1)); - JASSNATIVE native = get_native(name.c_str()); + //-------------------------------------------------------- + // JassNatives - if (!native.is_valid()) { - return 0; - } + int lua_invokeNative(lua_State* l) { + std::string name = lua_tostring(l, lua_upvalueindex(1)); + Jass::JASSNATIVE native = Jass::GetNative(name); - int size = native.get_params().size(); - if (size > lua_gettop(l)) { - return luaL_error(l, "function '%s' must have %d %s", name.c_str(), size, size > 1 ? "arguments" : "argument"); - } - - for (int i = 1; i <= size; i++) { - if (lua_isnil(l, i)) { - return luaL_error(l, "Argument number %d of function '%s' mustn't be equal to nil", i, name.c_str()); + if (!native.IsValid()) { + return 0; } - } - - size = lua_gettop(l); - - float* float_params = new float[size]; - DWORD* params = new DWORD[size]; - ZeroMemory(float_params, size); - ZeroMemory(params, size); - UINT i = 1; - - for (const auto& type : native.get_params()) { - switch (type) { - case TYPE_CODE: - if (lua_isinteger(l, i)) { - params[i - 1] = (DWORD)lua_tointeger(l, i); - } - else if (lua_isfunction(l, i)) { - params[i - 1] = to_code(l, i, (UINT)lua_touserdata(l, 1)); - } - - break; - case TYPE_BOOLEAN: - params[i - 1] = (DWORD)lua_toboolean(l, i); - - break; - case TYPE_HANDLE: - params[i - 1] = (DWORD)lua_touserdata(l, i); - - break; - case TYPE_INTEGER: - if (lua_isinteger(l, i)) { - params[i - 1] = (DWORD)lua_tointeger(l, i); + + std::size_t size = native.GetParams().size(); + std::vector floats; + std::vector params; + params.resize(size); + UINT i = 1; + + // Lua parameters -> Jass parameters + for (const auto& type : native.GetParams()) { + if (isupper(type[0])) { + switch (type[0]) { + case 'C': + if (lua_isfunction(l, i)) { + params[i - 1] = Jass::ToCode(l, i); + } + else { + return luaL_typeerror(l, i, "code"); + } + + break; + case 'B': + if (lua_isboolean(l, i)) { + params[i - 1] = (DWORD)lua_toboolean(l, i); + } + else { + return luaL_typeerror(l, i, "boolean"); + } + + break; + case 'I': + if (lua_isinteger(l, i)) { + params[i - 1] = (DWORD)lua_tointeger(l, i); + } + /*else if (lua_isstring(l, i) && strlen(lua_tostring(l, i)) == 4) { + params[i - 1] = Jass::ToID(lua_tostring(l, i)); + }*/ + else { + return luaL_typeerror(l, i, "integer"); + } + + break; + case 'R': { + if (lua_isnumber(l, i)) { + floats.push_back((float)lua_tonumber(l, i)); + params[i - 1] = (DWORD)&floats[floats.size() - 1]; + } + else { + return luaL_typeerror(l, i, "number"); + } + + break; + } + case 'S': + if (lua_isstring(l, i)) { + params[i - 1] = (UINT)&JassMachine::GetJassMachine()->string_table->GetRCString(Jass::ToString(lua_tostring(l, i))); + } + else { + return luaL_typeerror(l, i, "string"); + } + + break; + default: + params[i - 1] = NULL; + + break; + } } else { - params[i - 1] = to_ID(lua_tostring(l, i)); + if (!lua_isnil(l, i)) { + if (luaL_getmetafield(l, i, "__name") != LUA_TSTRING) { + return luaL_typeerror(l, i, type.c_str()); + } + + std::string metatype = std::string(lua_tostring(l, -1)); + lua_pop(l, 1); + + if (IsChild(type, metatype)) { + params[i - 1] = *(DWORD*)lua_touserdata(l, i); + } + else { + return luaL_typeerror(l, i, type.c_str()); + } + } } - break; - case TYPE_REAL: { - float_params[i - 1] = (float)lua_tonumber(l, i); - params[i - 1] = (DWORD)&(float_params[i - 1]); - - break; - } - case TYPE_STRING: - params[i - 1] = to_string(cp1251_to_utf8(lua_tostring(l, i)).c_str()); - - break; - default: - params[i - 1] = NULL; - - break; + i++; } - i++; - } - - BOOL result = native.call(params, size); - delete[] float_params; - delete[] params; - - switch (native.get_rettype()) { - case TYPE_BOOLEAN: - lua_pushboolean(l, result); - - break; - case TYPE_INTEGER: - if (name == "GetUnitTypeId" || name == "GetSpellAbilityId" || name == "GetItemTypeId") { - std::swap(((LPSTR)&result)[0], ((LPSTR)&result)[3]); - std::swap(((LPSTR)&result)[1], ((LPSTR)&result)[2]); - lua_pushlstring(l, (LPSTR)&result, 4); - } - else { - lua_pushinteger(l, result); + if (name == "Player" && (int)params[0] < 0) { + return luaL_error(l, "player expected positive index, received: %d", params[0]); } - break; - case TYPE_CODE: - lua_pushinteger(l, result); - - break; - case TYPE_HANDLE: - lua_pushlightuserdata(l, (PVOID)result); - - break; - case TYPE_REAL: - lua_pushnumber(l, from_real(result)); - - break; - case TYPE_STRING: - lua_pushstring(l, utf8_to_cp1251(from_string(getJassMachine()->string_table->get(result))).c_str()); - - break; - } - - return native.get_rettype() != TYPE_NOTHING ? 1 : 0; -} - -//-------------------------------------------------------- - -void lua_openJassNatives(lua_State* l) { - for (const auto& native : jassnatives) { - lua_registerJassNative(l, native.first, lua_callNative); - } -} - -//-------------------------------------------------------- -// MouseAPI - -//-------------------------------------------------------- - -//-------------------------------------------------------- -// FrameAPI - -int lua_SetUnitArmor(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetUnitArmor((UINT)lua_touserdata(l, 1), (float)lua_tonumber(l, 2)); - - return 0; -} - -int lua_GetUnitArmor(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushnumber(l, GetUnitArmor((UINT)lua_touserdata(l, 1))); - - return 1; -} - -int lua_GetUnitMaxLife(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushnumber(l, GetUnitMaxLife((UINT)lua_touserdata(l, 1))); - - return 1; -} - -int lua_SetUnitMaxLife(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetUnitMaxLife((UINT)lua_touserdata(l, 1), (float)lua_tonumber(l, 2)); - - return 0; -} - -int lua_GetUnitMaxMana(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushnumber(l, GetUnitMaxMana((UINT)lua_touserdata(l, 1))); - - return 1; -} - -int lua_SetUnitMaxMana(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetUnitMaxMana((UINT)lua_touserdata(l, 1), (float)lua_tonumber(l, 2)); - - return 0; -} - -int lua_GetUnitLifeRegen(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushnumber(l, GetUnitLifeRegen((UINT)lua_touserdata(l, 1))); - - return 1; -} - -int lua_SetUnitLifeRegen(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetUnitLifeRegen((UINT)lua_touserdata(l, 1), (float)lua_tonumber(l, 2)); - - return 0; -} - -int lua_GetUnitManaRegen(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushnumber(l, GetUnitManaRegen((UINT)lua_touserdata(l, 1))); - - return 1; -} - -int lua_SetUnitManaRegen(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetUnitManaRegen((UINT)lua_touserdata(l, 1), (float)lua_tonumber(l, 2)); - - return 0; -} - -int lua_GetUnitBaseDamage(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushinteger(l, GetUnitBaseDamage((UINT)lua_touserdata(l, 1))); - - return 1; -} - -int lua_SetUnitBaseDamage(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetUnitBaseDamage((UINT)lua_touserdata(l, 1), (UINT)lua_tointeger(l, 2)); - - return 0; -} - -int lua_GetUnitAttackSpeed(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushnumber(l, GetUnitAttackSpeed((UINT)lua_touserdata(l, 1))); - - return 1; -} - -int lua_SetUnitAttackSpeed(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetUnitAttackSpeed((UINT)lua_touserdata(l, 1), (float)lua_tonumber(l, 2)); - - return 0; -} - -int lua_UnitResetAttackCooldown(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushboolean(l, UnitResetAttackCooldown((UINT)lua_touserdata(l, 1))); - - return 1; -} - -int lua_GetItemBaseNameById(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushstring(l, utf8_to_cp1251(GetItemBaseNameById(to_ID(lua_tostring(l, 1)))).c_str()); - - return 1; -} - -int lua_SetItemBaseNameById(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetItemBaseNameById(to_ID(lua_tostring(l, 1)), cp1251_to_utf8(lua_tostring(l, 2)).c_str()); - - return 0; -} - -int lua_GetItemBaseUbertipById(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushstring(l, utf8_to_cp1251(GetItemBaseUbertipById(to_ID(lua_tostring(l, 1)))).c_str()); - - return 1; -} - -int lua_SetItemBaseUbertipById(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetItemBaseUbertipById(to_ID(lua_tostring(l, 1)), cp1251_to_utf8(lua_tostring(l, 2)).c_str()); - - return 0; -} - -int lua_GetItemBaseIconPathById(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushstring(l, utf8_to_cp1251(GetItemBaseIconPathById(to_ID(lua_tostring(l, 1)))).c_str()); - - return 1; -} - -int lua_SetItemBaseIconPathById(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetItemBaseIconPathById(to_ID(lua_tostring(l, 1)), cp1251_to_utf8(lua_tostring(l, 2)).c_str()); - - return 0; -} - -int lua_GetMouseWorldPos(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - PVECTOR3 mousePos = GetMouseWorldPos(); - - lua_pushnumber(l, mousePos->_x); - lua_pushnumber(l, mousePos->_y); - lua_pushnumber(l, mousePos->_z); - - return 3; -} - -int lua_GetMouseWorldX(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushnumber(l, GetMouseWorldX()); - - return 1; -} - -int lua_GetMouseWorldY(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushnumber(l, GetMouseWorldY()); - - return 1; -} - -int lua_GetMouseWorldZ(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushnumber(l, GetMouseWorldZ()); - - return 1; -} - -int lua_GetEffectPos(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - PVECTOR3 objectPos = GetEffectPos((UINT)lua_touserdata(l, 1)); - - lua_pushnumber(l, objectPos->_x); - lua_pushnumber(l, objectPos->_y); - lua_pushnumber(l, objectPos->_z); - - return 3; -} - -int lua_GetEffectX(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushnumber(l, GetEffectPos((UINT)lua_touserdata(l, 1))->_x); - - return 1; -} - -int lua_GetEffectY(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushnumber(l, GetEffectPos((UINT)lua_touserdata(l, 1))->_y); - - return 1; -} - -int lua_GetEffectZ(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushnumber(l, GetEffectPos((UINT)lua_touserdata(l, 1))->_z); - - return 1; -} - -int lua_SetEffectPos(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - UINT_PTR object = (UINT)lua_touserdata(l, 1); - - switch (lua_gettop(l)) - { - case 2: - SetEffectX(object, (float)lua_tonumber(l, 2)); - - break; - case 3: - SetEffectX(object, (float)lua_tonumber(l, 2)); - SetEffectY(object, (float)lua_tonumber(l, 3)); - - break; - case 4: - SetEffectPos(object, VECTOR3((float)lua_tonumber(l, 2), (float)lua_tonumber(l, 3), (float)lua_tonumber(l, 4))); - - break; - } - - return 0; -} - -int lua_SetEffectX(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetEffectX((UINT)lua_touserdata(l, 1), (float)lua_tonumber(l, 2)); - - return 0; -} - -int lua_SetEffectY(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetEffectY((UINT)lua_touserdata(l, 1), (float)lua_tonumber(l, 2)); - - return 0; -} - -int lua_SetEffectZ(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetEffectZ((UINT)lua_touserdata(l, 1), (float)lua_tonumber(l, 2)); - - return 0; -} - -//-------------------------------------------------------- - -//-------------------------------------------------------- -// FrameAPI - -int lua_GetOriginFrame(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushlightuserdata(l, (PVOID)GetOriginFrame((EOriginFrame)lua_tointeger(l, 1), (UINT)lua_tointeger(l, 2))); - - return 1; -} - -int lua_LoadTOCFile(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushboolean(l, LoadTOCFile(cp1251_to_utf8(lua_tostring(l, 1)).c_str())); - - return 1; -} - -int lua_GetFrameByName(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushlightuserdata(l, (PVOID)GetFrameByName(cp1251_to_utf8(lua_tostring(l, 1)).c_str(), (UINT)lua_tointeger(l, 2))); - - return 1; -} - -int lua_GetFrameParent(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushlightuserdata(l, (PVOID)GetFrameParent((UINT)lua_touserdata(l, 1))); - - return 1; -} - -int lua_GetFrameChildrenCount(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushinteger(l, GetFrameChildrenCount((UINT)lua_touserdata(l, 1))); - - return 1; -} - -int lua_GetFrameChild(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushlightuserdata(l, (PVOID)GetFrameChild((UINT)lua_touserdata(l, 1), (UINT)lua_tointeger(l, 2))); - - return 1; -} - -int lua_TriggerRegisterFrameEvent(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - TriggerRegisterFrameEvent((UINT)lua_touserdata(l, 1), (UINT)lua_touserdata(l, 2), (EFrameEvent)lua_tointeger(l, 3)); - - return 0; -} - -int lua_CreateFrame(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushlightuserdata(l, (PVOID)CreateFrame(cp1251_to_utf8(lua_tostring(l, 1)).c_str(), (UINT)lua_touserdata(l, 2), (EFramePoint)lua_tointeger(l, 3), (EFramePoint)lua_tointeger(l, 4) /*(UINT)lua_tointeger(l, 5)*/)); - - return 1; -} - -int lua_SetFrameText(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetFrameText((UINT)lua_touserdata(l, 1), cp1251_to_utf8(lua_tostring(l, 2)).c_str()); - - return 0; -} - -int lua_GetFrameText(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushstring(l, utf8_to_cp1251(GetFrameText((UINT)lua_touserdata(l, 1))).c_str()); - - return 1; -} - -int lua_SetFrameTextColor(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetFrameTextColor((UINT)lua_touserdata(l, 1), (BYTE)lua_tointeger(l, 2), (BYTE)lua_tointeger(l, 3), (BYTE)lua_tointeger(l, 4), (BYTE)lua_tointeger(l, 5)); - - return 0; -} - -int lua_GetFrameTextHeight(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushnumber(l, GetFrameTextHeight((UINT)lua_touserdata(l, 1))); - - return 1; -} - -int lua_SetFrameWidth(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetFrameWidth((UINT)lua_touserdata(l, 1), (float)lua_tonumber(l, 2)); - - return 0; -} - -int lua_SetFrameHeight(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetFrameHeight((UINT)lua_touserdata(l, 1), (float)lua_tonumber(l, 2)); - - return 0; -} - -int lua_SetFrameSize(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetFrameSize((UINT)lua_touserdata(l, 1), (float)lua_tonumber(l, 2), (float)lua_tonumber(l, 3)); + BOOL result = native.Invoke(params.data(), size); - return 0; -} -int lua_SetFrameScale(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetFrameScale((UINT)lua_touserdata(l, 1), (float)lua_tonumber(l, 2)); - - return 0; -} - -int lua_SetFrameAbsolutePoint(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetFrameAbsolutePoint((UINT)lua_touserdata(l, 1), (EFramePoint)lua_tointeger(l, 2), (float)lua_tonumber(l, 3), (float)lua_tonumber(l, 4)); - - return 0; -} - -int lua_SetFramePoint(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetFramePoint((UINT)lua_touserdata(l, 1), (EFramePoint)lua_tointeger(l, 2), (UINT)lua_touserdata(l, 3), (EFramePoint)lua_tointeger(l, 4), (float)lua_tonumber(l, 5), (float)lua_tonumber(l, 6)); - - return 0; -} - -int lua_GetFrameWidth(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushnumber(l, GetFrameWidth((UINT)lua_touserdata(l, 1))); - - return 1; -} - -int lua_GetFrameHeight(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushnumber(l, GetFrameHeight((UINT)lua_touserdata(l, 1))); - - return 1; -} - -int lua_GetFramePointParent(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushinteger(l, GetFramePointParent((UINT)lua_touserdata(l, 1), (EFramePoint)lua_tointeger(l, 2))); - - return 1; -} - -int lua_GetFramePointRelativePoint(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushinteger(l, GetFramePointRelativePoint((UINT)lua_touserdata(l, 1), (EFramePoint)lua_tointeger(l, 2))); - - return 1; -} - -int lua_GetFramePointX(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushnumber(l, GetFramePointX((UINT)lua_touserdata(l, 1), (EFramePoint)lua_tointeger(l, 2))); + // Jass return -> Lua return + std::string return_type = native.GetReturnType(); + if (isupper(return_type[0])) { + switch (return_type[0]) { + case 'B': + lua_pushboolean(l, result); - return 1; -} + break; + case 'I': + lua_pushinteger(l, result); -int lua_GetFramePointY(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - lua_pushnumber(l, GetFramePointY((UINT)lua_touserdata(l, 1), (EFramePoint)lua_tointeger(l, 2))); + break; + case 'C': + lua_pushinteger(l, result); - return 1; -} + break; + case 'R': + lua_pushnumber(l, Jass::FromReal(result)); -int lua_GetTriggerFrame(lua_State* l) { - lua_pushlightuserdata(l, (PVOID)GetTriggerFrame()); + break; + case 'S': + lua_pushstring(l, JassMachine::GetJassMachine()->string_table->GetString(result)); + //lua_pushstring(l, Jass::FromString(JassMachine::GetJassMachine()->string_table->Get(result))); - return 1; -} + break; + default: + return 0; + } + } + else { + result ? *(DWORD*)lua_newuserdata(l, sizeof(DWORD)) = result, luaL_setmetatable(l, return_type.c_str()) : lua_pushnil(l); + /*if (result) { + *(DWORD*)lua_newuserdata(l, sizeof(DWORD)) = result; + luaL_setmetatable(l, return_type.c_str()); + } + else { + lua_pushnil(l); + }*/ + } -int lua_GetFrameValue(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; + return 1; } - lua_pushnumber(l, GetFrameValue((UINT)lua_touserdata(l, 1))); - - return 1; -} - -int lua_GetTriggerFrameValue(lua_State* l) { - lua_pushnumber(l, GetTriggerFrameValue()); + //-------------------------------------------------------- - return 1; -} + int lua_handleequal(lua_State* l) { + PDWORD param1 = (PDWORD)lua_touserdata(l, 1); + PDWORD param2 = (PDWORD)lua_touserdata(l, 2); -int lua_SetFrameValue(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } - - SetFrameValue((UINT)lua_touserdata(l, 1), (float)lua_tonumber(l, 2)); - - return 0; -} + lua_pushboolean(l, (param1 ? *param1 : NULL) == (param2 ? *param2 : NULL)); -int lua_SetFrameMinMaxValue(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; + return 1; } - SetFrameMinMaxValue((UINT)lua_touserdata(l, 1), (float)lua_tonumber(l, 2), (float)lua_tonumber(l, 3)); - - return 0; -} - -int lua_SetFrameStepSize(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } + int lua_handletostring(lua_State* l) { + lua_getmetatable(l, 1); + lua_getfield(l, 2, "__name"); - SetFrameStepSize((UINT)lua_touserdata(l, 1), (float)lua_tonumber(l, 2)); + UINT handle = *(UINT*)lua_touserdata(l, 1); - return 0; -} + std::string string = Logger::format("%s: %08X", lua_tostring(l, 3), handle); + if (developerMode && handle > 0x100000) { + string += Logger::format(" | %08X", ConvertHandle(handle)); + } -int lua_SetFrameTexture(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; + lua_pop(l, 2); + + lua_pushstring(l, string.c_str()); + + return 1; } - SetFrameTexture((UINT)lua_touserdata(l, 1), cp1251_to_utf8(lua_tostring(l, 2)).c_str(), lua_toboolean(l, 3)); - - return 0; -} + int lua_close(lua_State* l) { + *(DWORD*)lua_touserdata(l, 1) = NULL; -int lua_SetFrameEnable(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; + return 0; } - SetFrameEnable((UINT)lua_touserdata(l, 1), lua_toboolean(l, 2)); + int IdToString(lua_State* l) { + if (lua_isinteger(l, 1)) { + DWORD id = (DWORD)lua_tointeger(l, 1); + std::reverse(&(((LPSTR)&id)[0]), &(((LPSTR)&id)[4])); + lua_pushlstring(l, (LPSTR)&id, 4); + } + else { + return luaL_typeerror(l, 1, "integer"); + } - return 0; -} -int lua_ClickFrame(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; + return 1; } - ClickFrame((UINT)lua_touserdata(l, 1)); - - return 0; -} + int StringToId(lua_State* l) { + if (lua_isstring(l, 1)) { + lua_pushinteger(l, Jass::ToID(lua_tostring(l, 1))); + } + else { + return luaL_typeerror(l, 1, "string"); + } -int lua_SetFrameModel(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; + return 1; } - SetFrameModel((UINT)lua_touserdata(l, 1), cp1251_to_utf8(lua_tostring(l, 2)).c_str(), (UINT)lua_tointeger(l, 3), (BOOL)lua_toboolean(l, 4)); - - return 0; -} + int FourCC(lua_State* l) { + if (lua_isinteger(l, 1)) { + IdToString(l); + } + else if (lua_isstring(l, 1)) { + StringToId(l); + } + else { + return luaL_typeerror(l, 1, "string or integer"); + } -int lua_DestroyFrame(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; + return 1; } - DestroyFrame((UINT)lua_touserdata(l, 1)); - - return 0; -} - -int lua_SetFrameVisible(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } + void lua_openJassNatives(lua_State* l) { + Jass::JassNativesReset(); + LuaMachine::HandleMetatablesReset(); + Jass::JassNativesParse(); - SetFrameVisible((UINT)lua_touserdata(l, 1), (BOOL)lua_toboolean(l, 2)); + for (const auto& type : LuaMachine::handlemetatypes) { + if (luaL_newmetatable(l, type.first.c_str())) { + lua_pushcfunction(l, lua_handleequal); + lua_setfield(l, -2, "__eq"); - return 0; -} + lua_pushcfunction(l, lua_handletostring); + lua_setfield(l, -2, "__tostring"); -int lua_SetGameUIVisible(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; - } + lua_pushstring(l, type.first.c_str()); + lua_setfield(l, -2, "__metatable"); - SetGameUIVisible((BOOL)lua_toboolean(l, 1)); + lua_pop(l, 1); + } + } - return 0; -} + for (const auto& native : Jass::jassnatives) { + lua_registerJassNative(l, native.first.c_str(), lua_invokeNative); + } -int lua_SetFrameCheck(lua_State* l) { - BOOL error = checkParams(l); - if (error) { - return error; + lua_register(l, "IdToString", IdToString); + lua_register(l, "StringToId", StringToId); + lua_register(l, "FourCC", FourCC); } - - SetFrameCheck((UINT)lua_touserdata(l, 1), (BOOL)lua_toboolean(l, 2)); - - return 0; -} - -//-------------------------------------------------------- - -int GetTrigger(lua_State* l) { - lua_pushlightuserdata(l, (PVOID)GetTimerByHandle((UINT)lua_touserdata(l, 1))); - - return 1; -} - -void lua_openMemHackAPI(lua_State* l) { - lua_registerex(l, "GetUnitArmor", 1, lua_GetUnitArmor); - lua_registerex(l, "SetUnitArmor", 2, lua_SetUnitArmor); - lua_registerex(l, "GetUnitMaxLife", 1, lua_GetUnitMaxLife); - lua_registerex(l, "SetUnitMaxLife", 2, lua_SetUnitMaxLife); - lua_registerex(l, "GetUnitMaxMana", 1, lua_GetUnitMaxMana); - lua_registerex(l, "SetUnitMaxMana", 2, lua_SetUnitMaxMana); - lua_registerex(l, "GetUnitLifeRegen", 1, lua_GetUnitLifeRegen); - lua_registerex(l, "SetUnitLifeRegen", 2, lua_SetUnitLifeRegen); - lua_registerex(l, "GetUnitManaRegen", 1, lua_GetUnitManaRegen); - lua_registerex(l, "SetUnitManaRegen", 2, lua_SetUnitManaRegen); - lua_registerex(l, "GetUnitBaseDamage", 1, lua_GetUnitBaseDamage); - lua_registerex(l, "SetUnitBaseDamage", 2, lua_SetUnitBaseDamage); - lua_registerex(l, "GetUnitAttackSpeed", 1, lua_GetUnitAttackSpeed); - lua_registerex(l, "SetUnitAttackSpeed", 2, lua_SetUnitAttackSpeed); - lua_registerex(l, "UnitResetAttackCooldown", 1, lua_UnitResetAttackCooldown); - lua_registerex(l, "GetItemBaseNameById", 1, lua_GetItemBaseNameById); - lua_registerex(l, "SetItemBaseNameById", 2, lua_SetItemBaseNameById); - lua_registerex(l, "GetItemBaseUbertipById", 1, lua_GetItemBaseUbertipById); - lua_registerex(l, "SetItemBaseUbertipById", 2, lua_SetItemBaseUbertipById); - lua_registerex(l, "GetItemBaseIconPathById", 1, lua_GetItemBaseIconPathById); - lua_registerex(l, "SetItemBaseIconPathById", 2, lua_SetItemBaseIconPathById); - lua_registerex(l, "GetMouseWorldPos", 0, lua_GetMouseWorldPos); - lua_registerex(l, "GetMouseWorldX", 0, lua_GetMouseWorldX); - lua_registerex(l, "GetMouseWorldY", 0, lua_GetMouseWorldY); - lua_registerex(l, "GetMouseWorldZ", 0, lua_GetMouseWorldZ); - lua_registerex(l, "GetEffectPos", 1, lua_GetEffectPos); - lua_registerex(l, "GetEffectX", 1, lua_GetEffectX); - lua_registerex(l, "GetEffectY", 1, lua_GetEffectY); - lua_registerex(l, "GetEffectZ", 1, lua_GetEffectZ); - lua_registerex(l, "SetEffectPos", 2, lua_SetEffectPos); - lua_registerex(l, "SetEffectX", 2, lua_SetEffectX); - lua_registerex(l, "SetEffectY", 2, lua_SetEffectY); - lua_registerex(l, "SetEffectZ", 2, lua_SetEffectZ); -} - -void lua_openFrameAPI(lua_State* l) { - lua_setint(l, "ORIGIN_FRAME_GAME_UI", ORIGIN_FRAME_GAME_UI); - lua_setint(l, "ORIGIN_FRAME_WORLD_FRAME", ORIGIN_FRAME_WORLD_FRAME); - lua_setint(l, "ORIGIN_FRAME_HERO_BAR", ORIGIN_FRAME_HERO_BAR); - lua_setint(l, "ORIGIN_FRAME_HERO_BUTTON", ORIGIN_FRAME_HERO_BUTTON); - lua_setint(l, "ORIGIN_FRAME_HERO_HP_BAR", ORIGIN_FRAME_HERO_HP_BAR); - lua_setint(l, "ORIGIN_FRAME_HERO_MANA_BAR", ORIGIN_FRAME_HERO_MANA_BAR); - lua_setint(l, "ORIGIN_FRAME_HERO_BUTTON_INDICATOR", ORIGIN_FRAME_HERO_BUTTON_INDICATOR); - lua_setint(l, "ORIGIN_FRAME_ITEM_BUTTON", ORIGIN_FRAME_ITEM_BUTTON); - lua_setint(l, "ORIGIN_FRAME_COMMAND_BUTTON", ORIGIN_FRAME_COMMAND_BUTTON); - lua_setint(l, "ORIGIN_FRAME_SYSTEM_BUTTON", ORIGIN_FRAME_SYSTEM_BUTTON); - lua_setint(l, "ORIGIN_FRAME_PORTRAIT", ORIGIN_FRAME_PORTRAIT); - lua_setint(l, "ORIGIN_FRAME_MINIMAP", ORIGIN_FRAME_MINIMAP); - lua_setint(l, "ORIGIN_FRAME_MINIMAP_BUTTON", ORIGIN_FRAME_MINIMAP_BUTTON); - lua_setint(l, "ORIGIN_FRAME_TOOLTIP", ORIGIN_FRAME_TOOLTIP); - lua_setint(l, "ORIGIN_FRAME_UBERTOOLTIP", ORIGIN_FRAME_UBERTOOLTIP); - lua_setint(l, "ORIGIN_FRAME_CHAT_MSG", ORIGIN_FRAME_CHAT_MSG); - lua_setint(l, "ORIGIN_FRAME_UNIT_MSG", ORIGIN_FRAME_UNIT_MSG); - lua_setint(l, "ORIGIN_FRAME_TOP_MSG", ORIGIN_FRAME_TOP_MSG); - - lua_setint(l, "FRAMEPOINT_TOPLEFT", FRAMEPOINT_TOPLEFT); - lua_setint(l, "FRAMEPOINT_TOP", FRAMEPOINT_TOP); - lua_setint(l, "FRAMEPOINT_TOPRIGHT", FRAMEPOINT_TOPRIGHT); - lua_setint(l, "FRAMEPOINT_LEFT", FRAMEPOINT_LEFT); - lua_setint(l, "FRAMEPOINT_CENTER", FRAMEPOINT_CENTER); - lua_setint(l, "FRAMEPOINT_RIGHT", FRAMEPOINT_RIGHT); - lua_setint(l, "FRAMEPOINT_BOTTOMLEFT", FRAMEPOINT_BOTTOMLEFT); - lua_setint(l, "FRAMEPOINT_BOTTOM", FRAMEPOINT_BOTTOM); - lua_setint(l, "FRAMEPOINT_BOTTOMRIGHT", FRAMEPOINT_BOTTOMRIGHT); - - lua_setint(l, "FRAMEEVENT_CONTROL_CLICK", FRAMEEVENT_CONTROL_CLICK); - lua_setint(l, "FRAMEEVENT_MOUSE_ENTER", FRAMEEVENT_MOUSE_ENTER); - lua_setint(l, "FRAMEEVENT_MOUSE_LEAVE", FRAMEEVENT_MOUSE_LEAVE); - lua_setint(l, "FRAMEEVENT_MOUSE_UP", FRAMEEVENT_MOUSE_UP); - lua_setint(l, "FRAMEEVENT_MOUSE_DOWN", FRAMEEVENT_MOUSE_DOWN); - lua_setint(l, "FRAMEEVENT_MOUSE_WHEEL", FRAMEEVENT_MOUSE_WHEEL); - lua_setint(l, "FRAMEEVENT_CHECKBOX_CHECKED", FRAMEEVENT_CHECKBOX_CHECKED); - lua_setint(l, "FRAMEEVENT_CHECKBOX_UNCHECKED", FRAMEEVENT_CHECKBOX_UNCHECKED); - lua_setint(l, "FRAMEEVENT_EDITBOX_TEXT_CHANGED", FRAMEEVENT_EDITBOX_TEXT_CHANGED); - lua_setint(l, "FRAMEEVENT_POPUPMENU_ITEM_CHANGED", FRAMEEVENT_POPUPMENU_ITEM_CHANGED); - lua_setint(l, "FRAMEEVENT_MOUSE_DOUBLECLICK", FRAMEEVENT_MOUSE_DOUBLECLICK); - lua_setint(l, "FRAMEEVENT_SPRITE_ANIM_UPDATE", FRAMEEVENT_SPRITE_ANIM_UPDATE); - lua_setint(l, "FRAMEEVENT_SLIDER_VALUE_CHANGED", FRAMEEVENT_SLIDER_VALUE_CHANGED); - lua_setint(l, "FRAMEEVENT_DIALOG_CANCEL", FRAMEEVENT_DIALOG_CANCEL); - lua_setint(l, "FRAMEEVENT_DIALOG_ACCEPT", FRAMEEVENT_DIALOG_ACCEPT); - lua_setint(l, "FRAMEEVENT_EDITBOX_ENTER", FRAMEEVENT_EDITBOX_ENTER); - - lua_registerex(l, "GetOriginFrame", 2, lua_GetOriginFrame); - lua_registerex(l, "LoadTOCFile", 1, lua_LoadTOCFile); - lua_registerex(l, "GetFrameByName", 2, lua_GetFrameByName); - lua_registerex(l, "GetFrameParent", 1, lua_GetFrameParent); - lua_registerex(l, "GetFrameChildrenCount", 1, lua_GetFrameChildrenCount); - lua_registerex(l, "GetFrameChild", 2, lua_GetFrameChild); - lua_registerex(l, "TriggerRegisterFrameEvent", 3, lua_TriggerRegisterFrameEvent); - lua_registerex(l, "CreateFrame", 4, lua_CreateFrame); - lua_registerex(l, "SetFrameText", 2, lua_SetFrameText); - lua_registerex(l, "GetFrameText", 1, lua_GetFrameText); - lua_registerex(l, "SetFrameTextColor", 5, lua_SetFrameTextColor); - lua_registerex(l, "GetFrameTextHeight", 1, lua_GetFrameTextHeight); - lua_registerex(l, "SetFrameWidth", 2, lua_SetFrameWidth); - lua_registerex(l, "SetFrameHeight", 2, lua_SetFrameHeight); - lua_registerex(l, "SetFrameSize", 3, lua_SetFrameSize); - lua_registerex(l, "SetFrameScale", 2, lua_SetFrameScale); - lua_registerex(l, "SetFrameAbsolutePoint", 4, lua_SetFrameAbsolutePoint); - lua_registerex(l, "SetFramePoint", 6, lua_SetFramePoint); - lua_registerex(l, "GetFrameWidth", 1, lua_GetFrameWidth); - lua_registerex(l, "GetFrameHeight", 1, lua_GetFrameHeight); - lua_registerex(l, "GetFramePointParent", 2, lua_GetFramePointParent); - lua_registerex(l, "GetFramePointRelativePoint", 2, lua_GetFramePointRelativePoint); - lua_registerex(l, "GetFramePointX", 2, lua_GetFramePointX); - lua_registerex(l, "GetFramePointY", 2, lua_GetFramePointY); - lua_registerex(l, "GetTriggerFrame", 0, lua_GetTriggerFrame); - lua_registerex(l, "GetFrameValue", 1, lua_GetFrameValue); - lua_registerex(l, "GetTriggerFrameValue", 0, lua_GetTriggerFrameValue); - lua_registerex(l, "SetFrameValue", 2, lua_SetFrameValue); - lua_registerex(l, "SetFrameMinMaxValue", 3, lua_SetFrameMinMaxValue); - lua_registerex(l, "SetFrameStepSize", 2, lua_SetFrameStepSize); - lua_registerex(l, "SetFrameTexture", 3, lua_SetFrameTexture); - lua_registerex(l, "SetFrameEnable", 2, lua_SetFrameEnable); - lua_registerex(l, "ClickFrame", 1, lua_ClickFrame); - lua_registerex(l, "SetFrameModel", 4, lua_SetFrameModel); - lua_registerex(l, "DestroyFrame", 1, lua_DestroyFrame); - lua_registerex(l, "SetFrameVisible", 2, lua_SetFrameVisible); - lua_registerex(l, "SetGameUIVisible", 1, lua_SetGameUIVisible); - lua_registerex(l, "SetFrameCheck", 2, lua_SetFrameCheck); } \ No newline at end of file diff --git a/Src/LuaFunctions.h b/Src/LuaFunctions.h index b657e19..b1f4d7b 100644 --- a/Src/LuaFunctions.h +++ b/Src/LuaFunctions.h @@ -1,10 +1,5 @@ #pragma once -#include -#include - -void lua_openJassNatives(lua_State* l); - -void lua_openMemHackAPI(lua_State* l); - -void lua_openFrameAPI(lua_State* l); \ No newline at end of file +namespace LuaFunctions { + void lua_openJassNatives(lua_State* l); +} \ No newline at end of file diff --git a/Src/LuaHooks.cpp b/Src/LuaHooks.cpp index 21a7639..c9f2af9 100644 --- a/Src/LuaHooks.cpp +++ b/Src/LuaHooks.cpp @@ -1,299 +1,288 @@ +#include "pch.h" #include "LuaHooks.h" -#include -#include -#include -#include "Global.h" +#include "EasyStormLib/EasyStormLib.h" +#include "Warcraft.h" -#include "MemHack.h" +namespace LuaHooks { + //--------------------------------------------------------------------------------- + // Loader lua from mpq -//--------------------------------------------------------------------------------- -// Loader lua from mpq - -int checkload(lua_State* L, int stat, const char* filename) { - if (stat) { - lua_pushstring(L, filename); - return 2; - } - else { - return luaL_error(L, "error loading module '%s' from file '%s':\n\t%s", lua_tostring(L, 1), filename, lua_tostring(L, -1)); + int checkload(lua_State* L, int stat, const char* filename) { + if (stat) { + lua_pushstring(L, filename); + return 2; + } + else { + return luaL_error(L, "error loading module '%s' from file '%s':\n\t%s", lua_tostring(L, 1), filename, lua_tostring(L, -1)); + } } -} - -int searcher_Lua(lua_State* l) { - HANDLE map = *pMapMpq; - - std::string scriptName = luaL_checkstring(l, 1) + std::string(".lua"); - lua_pop(l, 1); - char mapName[MAX_PATH] = { 0 }; - SFileGetArchiveName(map, mapName, sizeof(mapName)); - std::string scriptPath = mapName; + int searcher_Lua(lua_State* l) { + Storm::Archive map; + std::string scriptName = luaL_checkstring(l, 1); + if (!scriptName.compare("war3map")) { + map.Connect(*pMapMpq); + } - for (size_t i = scriptPath.size(); i > 0; i--) { - if (scriptPath[i] == '\\') { - scriptPath = scriptPath.substr(i + 1); + scriptName += std::string(".lua"); + lua_pop(l, 1); - break; + std::string mapPath = map.GetArchiveName(scriptName); + if (mapPath.empty()) { + map.Connect(*pMapMpq); + mapPath = map.GetArchiveName(); + map.Close(); } - } - scriptPath = "(" + scriptPath + "):\\" + scriptName; + std::string scriptPath = "(" + mapPath + "):\\" + scriptName; - HANDLE script; - if (SFileOpenFileEx(map, scriptName.c_str(), NULL, &script)) { - int lenght = SFileGetFileSize(script, NULL); - char* buffer = new char[lenght + 1]; + std::string script = map[scriptName]; + if (!script.empty()) { + return checkload(l, (luaL_loadbuffer(l, script.c_str(), script.size(), ("@" + scriptPath).c_str()) == LUA_OK), scriptName.c_str()); + } - ZeroMemory(buffer, lenght + 1); + lua_pushstring(l, ("no file '" + scriptPath + "'").c_str()); - SFileReadFile(script, buffer, lenght, NULL, NULL); - SFileCloseFile(script); + return 1; + } - int result = checkload(l, (luaL_loadbuffer(l, buffer, strlen(buffer), ("@" + scriptPath).c_str()) == LUA_OK), scriptName.c_str()); - delete[] buffer; + //-------------------------------------------------------------- - return result; - } + void lua_replaceSearchers(lua_State* l) { + std::vector searchers; - lua_pushstring(l, std::string("no file '" + scriptPath + "'").c_str()); + lua_getglobal(l, "package"); + lua_getfield(l, -1, "searchers"); - return 1; -} + if (developerMode) { + for (int i = 1; lua_rawgeti(l, -1, i); i++) { + searchers.push_back(lua_tocfunction(l, -1)); + lua_pop(l, 1); + } + lua_pop(l, 2); -//-------------------------------------------------------------- + searchers.insert(searchers.begin() + 1, searcher_Lua); + } + else { + lua_rawgeti(l, -1, 1); + searchers.push_back(lua_tocfunction(l, -1)); + lua_pop(l, 2); -void lua_replaceSearchers(lua_State* l) { - std::vector searchers; + searchers.push_back(searcher_Lua); + } - lua_getglobal(l, "package"); - lua_getfield(l, -1, "searchers"); + lua_newtable(l); - if (developerMode) { - for (int i = 1; lua_rawgeti(l, -1, i); i++) { - searchers.push_back(lua_tocfunction(l, -1)); - lua_pop(l, 1); + for (size_t i = 0; i < searchers.size(); i++) { + lua_pushvalue(l, -2); + lua_pushcclosure(l, searchers[i], 1); + lua_rawseti(l, -2, i + 1); } - lua_pop(l, 2); - searchers.insert(searchers.begin() + 1, searcher_Lua); - } - else { - lua_rawgeti(l, -1, 1); - searchers.push_back(lua_tocfunction(l, -1)); - lua_pop(l, 2); + lua_setfield(l, -2, "searchers"); - searchers.push_back(searcher_Lua); + lua_pop(l, 1); + searchers.clear(); } - lua_newtable(l); + // -------------------------------------------------------------------------------- - +// Disabled functions - for (size_t i = 0; i < searchers.size(); i++) { - lua_pushvalue(l, -2); - lua_pushcclosure(l, searchers[i], 1); - lua_rawseti(l, -2, i + 1); - } + void lua_disableFunctions(lua_State* l) { + lua_getglobal(l, "os"); - lua_setfield(l, -2, "searchers"); + std::vector functions = { "execute", "getenv", "setlocale", "tmpname" }; - lua_pop(l, 1); - searchers.clear(); -} + for (const auto& function : functions) { + lua_pushnil(l); + lua_setfield(l, -2, function); + } -// -------------------------------------------------------------------------------- - -// Disabled functions + lua_pop(l, 1); -void lua_disableFunctions(lua_State * l) { - lua_getglobal(l, "os"); + lua_getglobal(l, "io"); - std::vector functions = { "execute", "getenv", "setlocale", "tmpname" }; + functions = { "stdin", "stdout", "stderr", "flush", "input", "lines", "output", "popen", "tmpfile", "type" }; + + for (const auto& function : functions) { + lua_pushnil(l); + lua_setfield(l, -2, function); + } + + lua_pop(l, 1); - for (const auto& function : functions) { lua_pushnil(l); - lua_setfield(l, -2, function); + lua_setglobal(l, "dofile"); + + lua_pushnil(l); + lua_setglobal(l, "debug"); } - lua_pop(l, 1); + //--------------------------------------------------------------------------------- + // Utils - lua_getglobal(l, "io"); + BOOL isInGameCatalog(LPCSTR fileName) { + char filepath[MAX_PATH] = { 0 }; + GetFullPathName(fileName, sizeof(filepath), filepath, NULL); - functions = { "stdin", "stdout", "stderr", "flush", "input", "lines", "output", "popen", "tmpfile", "type" }; + char path[MAX_PATH] = { 0 }; + GetModuleFileName(GetModuleHandle(NULL), path, sizeof(path)); + for (int i = strlen(path); path[i] != '\\'; path[i] = NULL, i--); - for (const auto& function : functions) { - lua_pushnil(l); - lua_setfield(l, -2, function); + return !_strnicmp(filepath, path, strlen(path)) ? TRUE : FALSE; } - lua_pop(l, 1); + BOOL isAllowedExtension(LPCSTR fileName) { + char* fileextension = (char*)fileName + strlen(fileName); - lua_pushnil(l); - lua_setglobal(l, "dofile"); + for (; fileextension[0] != '.'; fileextension--); + fileextension++; -} + std::vector extensions = { "exe", "dll", "asi", "mix", "m3d", "mpq", "w3x", "w3m", "w3n" }; + for (const auto& extension : extensions) { + if (!_strnicmp(fileextension, extension, strlen(extension))) { + return FALSE; + } + } -//--------------------------------------------------------------------------------- -// Utils + return TRUE; + } -BOOL isInGameCatalog(LPCSTR fileName) { - char filepath[MAX_PATH] = { 0 }; - GetFullPathName(fileName, sizeof(filepath), filepath, NULL); + //--------------------------------------------------------------------------------- + // File stream only in catalog - char path[MAX_PATH] = { 0 }; - GetModuleFileName(GetModuleHandle(NULL), path, sizeof(path)); - for (int i = strlen(path); path[i] != '\\'; path[i] = NULL, i--); + // Open + luaL_Stream* newprefile(lua_State* L) { + luaL_Stream* p = (luaL_Stream*)lua_newuserdatauv(L, sizeof(luaL_Stream), 0); + p->closef = NULL; + luaL_setmetatable(L, LUA_FILEHANDLE); + return p; + } + + int io_fclose(lua_State* L) { + luaL_Stream* p = (luaL_Stream*)luaL_checkudata(L, 1, LUA_FILEHANDLE); + int res = fclose(p->f); + return luaL_fileresult(L, (res == 0), NULL); + } - return !_strnicmp(filepath, path, strlen(path)) ? TRUE : FALSE; -} + luaL_Stream* newfile(lua_State* L) { + luaL_Stream* p = newprefile(L); + p->f = NULL; + p->closef = &io_fclose; + return p; + } -BOOL isAllowedExtension(LPCSTR fileName) { - char* fileextension = (char*)fileName + strlen(fileName); + int l_checkmode(const char* mode) { + return (*mode != '\0' && strchr("rwa", *(mode++)) != NULL && (*mode != '+' || ((void)(++mode), 1)) && (strspn(mode, "b") == strlen(mode))); + } - for (; fileextension[0] != '.'; fileextension--); - fileextension++; + int io_open(lua_State* L) { + const char* filename = luaL_checkstring(L, 1); + const char* mode = luaL_optstring(L, 2, "r"); - std::vector extensions = { "exe", "dll", "asi", "mix", "m3d", "mpq", "w3x", "w3m", "w3n" }; - for (const auto& extension : extensions) { - if (!_strnicmp(fileextension, extension, strlen(extension))) { - return FALSE; + if (!isInGameCatalog(filename) /*|| !isAllowedExtension(filename)*/) { + return luaL_fileresult(L, FALSE, filename); } - } - return TRUE; -} - -//--------------------------------------------------------------------------------- -// File stream only in catalog - -// Open -luaL_Stream* newprefile(lua_State* L) { - luaL_Stream* p = (luaL_Stream*)lua_newuserdatauv(L, sizeof(luaL_Stream), 0); - p->closef = NULL; - luaL_setmetatable(L, LUA_FILEHANDLE); - return p; -} - -int io_fclose(lua_State* L) { - luaL_Stream* p = (luaL_Stream*)luaL_checkudata(L, 1, LUA_FILEHANDLE); - int res = fclose(p->f); - return luaL_fileresult(L, (res == 0), NULL); -} - -luaL_Stream* newfile(lua_State* L) { - luaL_Stream* p = newprefile(L); - p->f = NULL; - p->closef = &io_fclose; - return p; -} - -int l_checkmode(const char* mode) { - return (*mode != '\0' && strchr("rwa", *(mode++)) != NULL && (*mode != '+' || ((void)(++mode), 1)) && (strspn(mode, "b") == strlen(mode))); -} - -int io_open(lua_State* L) { - const char* filename = luaL_checkstring(L, 1); - const char* mode = luaL_optstring(L, 2, "r"); - - if (!isInGameCatalog(filename) || !isAllowedExtension(filename)) { - return luaL_fileresult(L, FALSE, filename); + luaL_Stream* p = newfile(L); + const char* md = mode; + luaL_argcheck(L, l_checkmode(md), 2, "invalid mode"); + fopen_s(&(p->f), filename, mode); + return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; } - luaL_Stream* p = newfile(L); - const char* md = mode; - luaL_argcheck(L, l_checkmode(md), 2, "invalid mode"); - fopen_s(&(p->f), filename, mode); - return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; -} + // Remove + int os_remove(lua_State* L) { + const char* filename = luaL_checkstring(L, 1); -// Remove -int os_remove(lua_State* L) { - const char* filename = luaL_checkstring(L, 1); + if (!isInGameCatalog(filename) /*|| !isAllowedExtension(filename)*/) { + return luaL_fileresult(L, FALSE, filename); + } - if (!isInGameCatalog(filename) || !isAllowedExtension(filename)) { - return luaL_fileresult(L, FALSE, filename); + return luaL_fileresult(L, remove(filename) == 0, filename); } - return luaL_fileresult(L, remove(filename) == 0, filename); -} + // Rename + int os_rename(lua_State* L) { + const char* fromname = luaL_checkstring(L, 1); + const char* toname = luaL_checkstring(L, 2); -// Rename -int os_rename(lua_State* L) { - const char* fromname = luaL_checkstring(L, 1); - const char* toname = luaL_checkstring(L, 2); + if (!isInGameCatalog(fromname) /*|| !isAllowedExtension(fromname)*/ || !isInGameCatalog(toname) /*|| !isAllowedExtension(toname)*/) { + return luaL_fileresult(L, FALSE, NULL); + } - if (!isInGameCatalog(fromname) || !isAllowedExtension(fromname) || !isInGameCatalog(toname) || !isAllowedExtension(toname)) { - return luaL_fileresult(L, FALSE, NULL); + return luaL_fileresult(L, rename(fromname, toname) == 0, NULL); } - return luaL_fileresult(L, rename(fromname, toname) == 0, NULL); -} + //--------------------------------------------------------------------------------- -//--------------------------------------------------------------------------------- + void lua_replaceFileStreamFunctions(lua_State* l) { + lua_getglobal(l, "io"); + lua_pushcfunction(l, io_open); + lua_setfield(l, -2, "open"); -void lua_replaceFileStreamFunctions(lua_State* l) { - lua_getglobal(l, "io"); - lua_pushcfunction(l, io_open); - lua_setfield(l, -2, "open"); + lua_pop(l, 1); - lua_pop(l, 1); + lua_getglobal(l, "os"); + lua_pushcfunction(l, os_remove); + lua_setfield(l, -2, "remove"); - lua_getglobal(l, "os"); - lua_pushcfunction(l, os_remove); - lua_setfield(l, -2, "remove"); + lua_pushcfunction(l, os_rename); + lua_setfield(l, -2, "rename"); - lua_pushcfunction(l, os_rename); - lua_setfield(l, -2, "rename"); + lua_pop(l, 1); + } - lua_pop(l, 1); -} + //--------------------------------------------------------------------------------- + // print -//--------------------------------------------------------------------------------- -// print + int lua_printc(lua_State* L) { + int n = lua_gettop(L); + int i; -int lua_printc(lua_State* L) { - int n = lua_gettop(L); - int i; + for (i = 1; i <= n; i++) { + size_t l; + LPCSTR s = luaL_tolstring(L, i, &l); - for (i = 1; i <= n; i++) { - size_t l; - LPCSTR s = luaL_tolstring(L, i, &l); + if (i > 1) { + lua_writestring("\t", 1); + } - if (i > 1) { - lua_writestring("\t", 1); + lua_writestring(s, l); + lua_pop(L, 1); } - lua_writestring(s, l); - lua_pop(L, 1); - } + lua_writeline(); - lua_writeline(); + return 0; + } - return 0; -} + int lua_print(lua_State* L) { + int n = lua_gettop(L); + int i; -int lua_print(lua_State* L) { - int n = lua_gettop(L); - int i; + for (i = 1; i <= n; i++) { + size_t l; + LPCSTR s = luaL_tolstring(L, i, &l); - for (i = 1; i <= n; i++) { - size_t l; - LPCSTR s = luaL_tolstring(L, i, &l); + if (i > 1) { + PrintChat("\t", 60.f); + } - if (i > 1) { - printChat("\t", 60.f); + PrintChat(luaL_tolstring(L, -1, NULL), 60.f); + lua_pop(L, 1); } - printChat(luaL_tolstring(L, -1, NULL), 60.f); - lua_pop(L, 1); + return 0; } - return 0; -} + //--------------------------------------------------------------------------------- -//--------------------------------------------------------------------------------- + void lua_replaceGlobals(lua_State* l) { + lua_pushcfunction(l, lua_printc); + lua_setglobal(l, "printc"); -void lua_replaceGlobals(lua_State* l) { - lua_pushcfunction(l, lua_printc); - lua_setglobal(l, "printc"); - - lua_pushcfunction(l, lua_print); - lua_setglobal(l, "print"); + lua_pushcfunction(l, lua_print); + lua_setglobal(l, "print"); + } } \ No newline at end of file diff --git a/Src/LuaHooks.h b/Src/LuaHooks.h index 134fc5a..49c0136 100644 --- a/Src/LuaHooks.h +++ b/Src/LuaHooks.h @@ -1,9 +1,8 @@ #pragma once -#include -#include - -void lua_replaceSearchers(lua_State* l); -void lua_disableFunctions(lua_State* l); -void lua_replaceFileStreamFunctions(lua_State* l); -void lua_replaceGlobals(lua_State* l); \ No newline at end of file +namespace LuaHooks { + void lua_replaceSearchers(lua_State* l); + void lua_disableFunctions(lua_State* l); + void lua_replaceFileStreamFunctions(lua_State* l); + void lua_replaceGlobals(lua_State* l); +} \ No newline at end of file diff --git a/Src/LuaMachine.cpp b/Src/LuaMachine.cpp index e7b993c..18b379c 100644 --- a/Src/LuaMachine.cpp +++ b/Src/LuaMachine.cpp @@ -1,189 +1,175 @@ +#include "pch.h" #include "LuaMachine.h" -#include "LuaFunctions.h" -#include "LuaHooks.h" #include "JassMachine.h" +#include "EasyStormLib/EasyStormLib.h" #include "JassNatives.h" -#include "GameUI.h" -#include "MemHack.h" -#include "Utils.h" -#include "Global.h" -#include - -lua_State* mainState; +#include "LuaHooks.h" +#include "LuaFunctions.h" +#include "Logger.h" -void lua_throwerr(lua_State* l); +namespace LuaMachine { + lua_State* mainState = NULL; -int stacktrace(lua_State* L); + void lua_throwerr(lua_State* l); -//---------------------------------------------------------- + int stacktrace(lua_State* L); -lua_State* getMainState() { - if (!mainState) { - lua_State* l = mainState = luaL_newstate(); + //---------------------------------------------------------- - luaL_openlibs(l); - if (!developerMode) { - lua_disableFunctions(l); - lua_replaceFileStreamFunctions(l); - } - lua_replaceGlobals(l); - lua_openJassNatives(l); - lua_openMemHackAPI(l); - lua_openFrameAPI(l); - // lua_open_warcraftfunctions(l); - lua_replaceSearchers(l); - } + lua_State* GetMainState() { + if (!mainState) { + lua_State* l = mainState = luaL_newstate(); + luaL_openlibs(l); + LuaHooks::lua_replaceSearchers(l); + LuaHooks::lua_replaceGlobals(l); - return mainState; -} + if (!developerMode) { + LuaHooks::lua_disableFunctions(l); + LuaHooks::lua_replaceFileStreamFunctions(l); + } -void destroyMainState() -{ - if (mainState) { - lua_close(mainState); - mainState = NULL; + LuaFunctions::lua_openJassNatives(l); + } - JassNatives_reset(); - GameUI_reset(); - MemHack_reset(); + return mainState; } - clearConsole(); -} + void DestroyLua() { + if (mainState) { + lua_close(mainState); + mainState = NULL; + Jass::JassOpcodesReset(); + } -//---------------------------------------------------------- + Logger::ClearConsole(); + } -BOOL startLua() { - destroyMainState(); - lua_State* l = getMainState(); - HANDLE war3luaScript; - BOOL result = 0; + void StartLua() { + DestroyLua(); - if (SFileOpenFileEx(*pMapMpq, "war3map.lua", NULL, &war3luaScript)) { - SFileCloseFile(war3luaScript); + lua_State* l = GetMainState(); + Storm::Archive map; + map.Connect(*pMapMpq); + if (!map["war3map.lua"].empty()) { + lua_pushcfunction(l, stacktrace); + lua_getglobal(l, "require"); + lua_pushstring(l, "war3map"); + if (lua_pcall(l, 1, LUA_MULTRET, -3) != LUA_OK) { + lua_throwerr(l); + } - lua_getglobal(l, "require"); - lua_pushstring(l, "war3map"); - if (!(result = !lua_pcall(l, 1, LUA_MULTRET, NULL))) { - lua_throwerr(l); + lua_pop(l, 2); } - - lua_pop(l, 1); } - return result; -} + BOOL __stdcall StartLuaThread() { + JassMachine::PJASS_INSTANCE JassVM = JassMachine::GetJassInstance(); + JassMachine::PJASS_STACK stack = JassVM->stack; -BOOL __stdcall startLuaThread(DWORD esi) { - PJASS_STACK stack = *(PJASS_STACK*)(esi + 0x2868); + lua_State* l = GetMainState(); + lua_State* thread = lua_newthread(l); + GetFunctionByRef(thread, stack->Pop()->value); + lua_pop(l, 1); - lua_State* l = (lua_State*)stack->pop()->value; - getFunctionByRef(l, stack->pop()->value); - UINT objectHandle = stack->pop()->value; - lua_State* thread = getThreadState(l, -1); - lua_xmove(l, thread, 1); + if (!lua_isfunction(thread, -1)) { + lua_pop(thread, 1); + lua_pushstring(thread, "Couldn't start the thread. Write to me at XGM or VK."); - int res; - //lua_pushcfunction(l, stacktrace); - switch (lua_resume(thread, l, 0, &res)) { /*lua_resume(thread, l, 0, &res) */ - case LUA_OK: - ((PJASS_DATA_SLOT)(esi + 80))->set(lua_toboolean(thread, 1), OPCODE_VARIABLE_BOOLEAN); + goto Error; + } - break; - case LUA_ERRRUN: - UINT object = GetTriggerByHandle(objectHandle) | GetTimerByHandle(objectHandle) | GetGroupByHandle(objectHandle); + int res; + switch (lua_resume(thread, l, 0, &res)) { + case LUA_OK: + JassVM->condition_return_value.Set(lua_toboolean(thread, 1), JassMachine::OPCODE_VARIABLE_BOOLEAN); - if (object) { - ((UINT(__fastcall*)(UINT))(*(UINT*)(*(UINT*)object + 0x5c)))(object); - } - lua_throwerr(thread); + break; + case LUA_ERRRUN: + Error: + PVOID handle = ConvertHandle(Jass::GetNative("GetTriggeringTrigger").Invoke(NULL, NULL) | Jass::GetNative("GetExpiredTimer").Invoke(NULL, NULL)); - return FALSE; - } + if (handle) { + fast_call((*(UINT*)(*(UINT*)handle + 0x5c)), handle); + } - return TRUE; -} + lua_throwerr(thread); -//---------------------------------------------------------- + return FALSE; + } -void lua_throwerr(lua_State* l) { - luaL_traceback(l, l, lua_tostring(l, -1), 0); - LPCSTR error = lua_tostring(l, -1); - lua_pop(l, 1); + return TRUE; + } - printf("\n%s--------------------Lua Error--------------------%s\n%s\n%s-------------------------------------------------%s\n\n", ANSI_COLOR_RED, ANSI_COLOR_RESET, error, ANSI_COLOR_RED, ANSI_COLOR_RESET); - printfChat(100, "\n|cFFFF0000--------------------Lua Error--------------------|r\n%s\n|cFFFF0000------------------------------------------------------------|r\n\n", error); -} + //---------------------------------------------------------- -int stacktrace(lua_State* L) { - luaL_traceback(L, L, lua_tostring(L, -1), 0); + void HandleMetatablesReset() { + std::map().swap(LuaMachine::handlemetatypes); + } - return 1; -} + BOOL GetGlobalTable(lua_State* l, LPCSTR name, bool weak) { + lua_getfield(l, LUA_REGISTRYINDEX, name); -//---------------------------------------------------------- + if (!lua_istable(l, -1)) { + lua_pop(l, 1); + lua_newtable(l); -lua_State* getThreadState(lua_State* l, int index) { - lua_pushvalue(l, index); - getGlobalTable(l, "_LUA_THREADS", false); - lua_pushvalue(l, -2); + if (weak) { + lua_newtable(l); + lua_pushstring(l, "__mode"); + lua_pushstring(l, "kv"); + lua_rawset(l, -3); - if (lua_rawget(l, -2) != LUA_TTHREAD) { - lua_pop(l, 1); - lua_newthread(l); - lua_pushvalue(l, -3); - lua_pushvalue(l, -2); - lua_rawset(l, -4); - } + lua_setmetatable(l, -2); + } - lua_State* thread = lua_tothread(l, -1); - lua_pop(l, 3); + lua_pushvalue(l, -1); + lua_setfield(l, LUA_REGISTRYINDEX, name); - return thread; -} + return FALSE; + } -BOOL getGlobalTable(lua_State* l, LPCSTR name, bool weak) { - lua_getfield(l, LUA_REGISTRYINDEX, name); + return TRUE; + } - if (!lua_istable(l, -1)) { - lua_pop(l, 1); - lua_newtable(l); + int PushFunctionRef(lua_State* l, int index) { + lua_pushvalue(l, index); // 1 + + GetGlobalTable(l, "_LUA_FUNCTIONS_REF", false); // 2 + - if (weak) { - lua_newtable(l); - lua_pushstring(l, "__mode"); - lua_pushstring(l, "kv"); - lua_rawset(l, -3); + int ref = (int)lua_rawlen(l, -1); + lua_pushvalue(l, -2); // 3 + + lua_rawseti(l, -2, ++ref); // 2 - - lua_setmetatable(l, -2); - } + lua_pop(l, 2); // 0 - - lua_pushvalue(l, -1); - lua_setfield(l, LUA_REGISTRYINDEX, name); + return ref; + } - return FALSE; + void GetFunctionByRef(lua_State* l, int ref) { + GetGlobalTable(l, "_LUA_FUNCTIONS_REF", false); // 1 + + lua_rawgeti(l, -1, ref); // 2 + + lua_remove(l, -2); // 1 - } - return TRUE; -} + //---------------------------------------------------------- -int pushFunctionRef(lua_State* l, int index) { - lua_pushvalue(l, index); - getGlobalTable(l, "_LUA_FUNCTIONS_REF", false); + void lua_throwerr(lua_State* l) { + std::string error = lua_tostring(l, -1); + Logger::Log(Logger::LOG_LEVEL::LOG_ERROR, error.c_str()); + PrintfChat(100, "\n[|cFFFF0000Error|r] %s\n\n", error.c_str()); + //printf("\n%s--------------------Lua Error--------------------%s\n%s\n%s-------------------------------------------------%s\n\n", ANSI_COLOR_RED, ANSI_COLOR_RESET, error, ANSI_COLOR_RED, ANSI_COLOR_RESET); + //printfChat(100, "\n|cFFFF0000--------------------Lua Error--------------------|r\n%s\n|cFFFF0000------------------------------------------------------------|r\n\n", error); + } - int ref = (int)lua_rawlen(l, -1); - lua_pushvalue(l, -2); - lua_rawseti(l, -2, ++ref); + int stacktrace(lua_State* L) + { + luaL_traceback(L, L, lua_tostring(L, -1), 0); - lua_pop(l, 2); + return 1; + } - return ref; -} + //---------------------------------------------------------- -void getFunctionByRef(lua_State* l, int ref) { - getGlobalTable(l, "_LUA_FUNCTIONS_REF", false); - lua_rawgeti(l, -1, ref); - lua_remove(l, -2); + std::map handlemetatypes; } \ No newline at end of file diff --git a/Src/LuaMachine.h b/Src/LuaMachine.h index 14ef435..42330ba 100644 --- a/Src/LuaMachine.h +++ b/Src/LuaMachine.h @@ -1,16 +1,14 @@ #pragma once -#include -#include +namespace LuaMachine { + extern std::map handlemetatypes; -BOOL startLua(); + void StartLua(); + BOOL __stdcall StartLuaThread(); -BOOL __stdcall startLuaThread(DWORD esi); + void HandleMetatablesReset(); + BOOL GetGlobalTable(lua_State* l, LPCSTR name, bool weak); -lua_State* getThreadState(lua_State* l, int index); - -BOOL getGlobalTable(lua_State* l, LPCSTR name, bool weak); - -int pushFunctionRef(lua_State* l, int index); - -void getFunctionByRef(lua_State* l, int ref); \ No newline at end of file + int PushFunctionRef(lua_State* l, int index); + void GetFunctionByRef(lua_State* l, int ref); +} \ No newline at end of file diff --git a/Src/MemHack.cpp b/Src/MemHack.cpp deleted file mode 100644 index d5a22f3..0000000 --- a/Src/MemHack.cpp +++ /dev/null @@ -1,489 +0,0 @@ -#include "Global.h" -#include "MemHack.h" - -auto GetDataNode = (UINT(__fastcall*)(UINT))((UINT_PTR)gameBase + 0x4c8520); -auto GetAgentBaseData = (UINT(__fastcall*)(UINT, UINT, UINT, UINT))((UINT_PTR)gameBase + 0x2b88a0); -auto GetAgentBaseUIData = (UINT(__fastcall*)(UINT, UINT, UINT, UINT))((UINT_PTR)gameBase + 0x319810); -UINT pUnitUIDataNode = (UINT)gameBase + 0xab58d4; -UINT pGameState = (UINT)gameBase + 0xab65f4; -UINT pGameClass1 = (UINT)gameBase + 0xab7788; -UINT pGameClass2 = (UINT)gameBase + 0xab4f80; - -std::vector stringPool; - -void printChat(LPCSTR text, float duration) { - ((void(__fastcall*)(UINT, UINT, UINT, UINT, LPCSTR, UINT, UINT))((UINT)gameBase + 0x2f8e40))(*(UINT*)pGameClass2, NULL, 0, 0, text, *(UINT*)&duration, 0xFFFFFFFF); -} - -void printfChat(float duration, LPCSTR format, ...) { - char text[8192] = { NULL }; - - va_list args; - va_start(args, format); - vsprintf_s(text, format, args); - va_end(args); - - printChat(text, duration); -} - -UINT GetAgentBaseDataById(UINT pAgentDataNode, UINT agentId) { - UINT retval = NULL; - - if (agentId) { - UINT pData = GetDataNode((UINT)&agentId); - - if (pData) { - return GetAgentBaseData(pAgentDataNode, NULL, pData, (UINT)&agentId); - } - } - - return retval; -} - -UINT GetAgentBaseUIDataById(UINT pAgentDataUINode, UINT agentId) { - UINT retval = NULL; - - if (agentId) { - UINT pData = GetDataNode((UINT)&agentId); - - if (pData) { - return GetAgentBaseUIData(pAgentDataUINode, NULL, pData, (UINT)&agentId); - } - } - - return retval; -} - -UINT GetWidgetBaseDataByIdCachingEx(UINT pDataNode, UINT index, UINT id, BOOL mode) { - UINT pData = NULL; - - if (id) { - switch (mode) - { - case 0: - pData = GetAgentBaseDataById(pDataNode, id); - - break; - case 1: - pData = GetAgentBaseUIDataById(pDataNode, id); - - break; - } - } - - return pData; -} - -UINT GetWidgetBaseUIDataByIdCaching(UINT pDataNode, UINT id) { - return GetWidgetBaseDataByIdCachingEx(pDataNode, 3, id, 1); -} - -void SetWidgetBaseUIStringParamById(UINT pDataNode, UINT id, UINT pointerLevel, UINT offset, LPCSTR string) { - if (!id) { - return; - } - - UINT pData = GetWidgetBaseUIDataByIdCaching(pDataNode, id); - if (!pData) { - return; - } - - pData += offset; - - switch (pointerLevel) - { - case 0: - for (size_t i = 0; i < stringPool.size(); i++) { - if (stringPool[i].c_str() == *(LPCSTR*)pData) { - stringPool.erase(stringPool.begin() + i); - - break; - } - } - - stringPool.push_back(string); - - *(LPCSTR*)pData = stringPool[stringPool.size() - 1].c_str(); - - break; - case 1: - if (!*(UINT*)pData) { - stringPool.push_back({0, 0, 0, 0}); - - *(LPCSTR*)pData = stringPool[stringPool.size() - 1].c_str(); - } - - for (size_t i = 0; i < stringPool.size(); i++) { - if (stringPool[i].c_str() == **(LPCSTR**)pData) { - stringPool.erase(stringPool.begin() + i); - - break; - } - } - - stringPool.push_back(string); - - **(LPCSTR**)pData = stringPool[stringPool.size() - 1].c_str(); - - break; - } -} - -LPCSTR GetWidgetBaseUIStringParamById(UINT pDataNode, UINT id, UINT pointerLevel, UINT offset) { - LPCSTR retval = NULL; - - if (id) { - UINT pData = GetWidgetBaseUIDataByIdCaching(pDataNode, id); - if (pData) { - pData = *(UINT*)(pData + offset); - if (pData) { - if (pointerLevel == 1) { - pData = *(UINT*)pData; - } - - if (pData) - { - retval = (LPCSTR)pData; - } - } - } - } - return retval; -} - -LPCSTR GetItemBaseUIStringParamById(UINT itemId, UINT pointerLevel, UINT offset) { - return GetWidgetBaseUIStringParamById(pUnitUIDataNode, itemId, pointerLevel, offset); -} - -void SetItemBaseUIStringParamById(UINT itemId, UINT pointerLevel, UINT offset, LPCSTR string) { - SetWidgetBaseUIStringParamById(pUnitUIDataNode, itemId, pointerLevel, offset, string); -} - -UINT ConvertHandleToObject(UINT handle) { - return handle ? *(UINT*)(*(UINT*)(*(UINT*)(*(UINT*)pGameState + 0x1c) + 0x19c) + handle * 0xc - 0x2fffff * 4) : NULL; -} - -UINT GetUnitAddressFloatsRelated(UINT pConvertedHandle, UINT step) { - return pConvertedHandle ? *(UINT*)(*(UINT*)(pConvertedHandle + step) * 8 + *(UINT*)(*(UINT*)pGameClass1 + 0xc) + 4) : NULL; -} - -UINT GetUnitAttackAbility(UINT unit) { - UINT pData = ConvertHandleToObject(unit); - - return pData ? *(UINT*)(pData + 0x1e8) : NULL; -} - -UINT GetUnitAttackOffsetValue(UINT unit, UINT offset) { - UINT pData = GetUnitAttackAbility(unit); - - return pData ? *(UINT*)(pData + offset) : 0; -} - -void SetUnitAttackOffsetValue(UINT unit, UINT offset, UINT value) { - UINT pData = GetUnitAttackAbility(unit); - - if (pData) { - *(UINT*)(pData + offset) = value; - } -} - -float GetUnitAttackSpeed(UINT unit) { - UINT speed = GetUnitAttackOffsetValue(unit, 0x1b0); - - return *(float*)&speed; -} - -void SetUnitAttackSpeed(UINT unit, float speed) { - SetUnitAttackOffsetValue(unit, 0x1b0, *(UINT*)&speed); -} - -BOOL UnitResetAttackCooldown(UINT unit) { - UINT pData = GetUnitAttackAbility(unit); - - if (pData) { - pData = *(UINT*)(pData + 0x1e4); - - if (pData) { - *(float*)(pData + 0x1e4) = 0.f; - - return true; - } - } - - return false; -} - -PVECTOR3 GetObjectPos(UINT object) { - UINT pData = ConvertHandleToObject(object); - - return pData ? (PVECTOR3)(*(UINT*)(pData + 0x28) + 0xC0) : NULL; -} - -float GetObjectX(UINT object) { - PVECTOR3 objectPos = GetObjectPos(object); - - return objectPos ? objectPos->_x : 0.f; -} - -float GetObjectY(UINT object) { - PVECTOR3 objectPos = GetObjectPos(object); - - return objectPos ? objectPos->_y : 0.f; -} - -float GetObjectZ(UINT object) { - PVECTOR3 objectPos = GetObjectPos(object); - - return objectPos ? objectPos->_z : 0.f; -} - -void SetObjectPos(UINT object, const VECTOR3& pos) { - PVECTOR3 objectPos = GetObjectPos(object); - - if (!objectPos) { - return; - } - - objectPos->operator=(pos); -} - -void SetObjectX(UINT object, float x) { - PVECTOR3 objectPos = GetObjectPos(object); - - if (!objectPos) { - return; - } - - objectPos->_x = x; -} - -void SetObjectY(UINT object, float y) { - PVECTOR3 objectPos = GetObjectPos(object); - - if (!objectPos) { - return; - } - - objectPos->_y = y; -} - -void SetObjectZ(UINT object, float z) { - PVECTOR3 objectPos = GetObjectPos(object); - - if (!objectPos) { - return; - } - - objectPos->_z = z; -} - -//------------------------------------------------------------------------ -// Lua references - -float GetUnitArmor(UINT unit) { - UINT pData = ConvertHandleToObject(unit); - - return pData ? *(float*)(pData + 0xe0) : 0.f; -} - -void SetUnitArmor(UINT unit, float armorValue) { - UINT pData = ConvertHandleToObject(unit); - - if (pData) { - *(float*)(pData + 0xe0) = armorValue; - } -} - -float GetUnitMaxLife(UINT unit) { - UINT pData = ConvertHandleToObject(unit); - float hp = 0.f; - - if (pData) { - pData = GetUnitAddressFloatsRelated(pData, 0xa0); - if (pData) { - hp = *(float*)(pData + 0x84); - } - } - - return hp; -} - -void SetUnitMaxLife(UINT unit, float hp) { - UINT pData = ConvertHandleToObject(unit); - - if (pData) { - pData = GetUnitAddressFloatsRelated(pData, 0xa0); - if (pData) { - *(float*)(pData + 0x84) = hp; - } - } -} - -float GetUnitMaxMana(UINT unit) { - UINT pData = ConvertHandleToObject(unit); - float hp = 0.f; - - if (pData) { - pData = GetUnitAddressFloatsRelated(pData, 0xc0); - if (pData) { - hp = *(float*)(pData + 0x84); - } - } - - return hp; -} - -void SetUnitMaxMana(UINT unit, float mana) { - UINT pData = ConvertHandleToObject(unit); - - if (pData) { - pData = GetUnitAddressFloatsRelated(pData, 0xc0); - if (pData) { - *(float*)(pData + 0x84) = mana; - } - } -} - -float GetUnitLifeRegen(UINT unit) { - UINT pData = ConvertHandleToObject(unit); - float lifeRegen = 0.f; - - if (pData) { - pData = GetUnitAddressFloatsRelated(pData, 0xa0); - if (pData) { - lifeRegen = *(float*)(pData + 0x7c); - } - } - - return lifeRegen; -} - -void SetUnitLifeRegen(UINT unit, float lifeRegen) { - UINT pData = ConvertHandleToObject(unit); - - if (pData) { - pData = GetUnitAddressFloatsRelated(pData, 0xa0); - if (pData) { - *(float*)(pData + 0x7c) = lifeRegen; - } - } -} - -float GetUnitManaRegen(UINT unit) { - UINT pData = ConvertHandleToObject(unit); - float manaRegen = 0.f; - - if (pData) { - pData = GetUnitAddressFloatsRelated(pData, 0xc0); - if (pData) { - manaRegen = *(float*)(pData + 0x7c); - } - } - - return manaRegen; -} - -void SetUnitManaRegen(UINT unit, float manaRegen) { - UINT pData = ConvertHandleToObject(unit); - - if (pData) { - pData = GetUnitAddressFloatsRelated(pData, 0xc0); - if (pData) { - *(float*)(pData + 0x7c) = manaRegen; - } - } -} - -UINT GetUnitBaseDamage(UINT unit) { - return GetUnitAttackOffsetValue(unit, 0xa0); -} - -void SetUnitBaseDamage(UINT unit, UINT damage) { - SetUnitAttackOffsetValue(unit, 0xa0, damage); -} - -LPCSTR GetItemBaseNameById(UINT itemId) { - return GetItemBaseUIStringParamById(itemId, 1, 0x2c); -} - -void SetItemBaseNameById(UINT itemId, LPCSTR name) { - SetItemBaseUIStringParamById(itemId, 1, 0x2c, name); -} - -LPCSTR GetItemBaseUbertipById(UINT itemId) { - return GetItemBaseUIStringParamById(itemId, 1, 0x26c); -} - -void SetItemBaseUbertipById(UINT itemId, LPCSTR ubertip) { - SetItemBaseUIStringParamById(itemId, 1, 0x26c, ubertip); -} - -LPCSTR GetItemBaseIconPathById(UINT itemId) { - return GetItemBaseUIStringParamById(itemId, 1, 0x24c); -} - -void SetItemBaseIconPathById(UINT itemId, LPCSTR path) { - SetItemBaseUIStringParamById(itemId, 1, 0x24c, path); -} - -PVECTOR3 GetMouseWorldPos() { - UINT pWorldFrame = *(UINT*)(*(UINT*)pGameClass2 + 0x3bc); - - return pWorldFrame ? (PVECTOR3)(pWorldFrame + 0x310) : NULL; -} - -float GetMouseWorldX() { - PVECTOR3 mousePos = GetMouseWorldPos(); - - return mousePos ? mousePos->_x : 0.f; -} - -float GetMouseWorldY() { - PVECTOR3 mousePos = GetMouseWorldPos(); - - return mousePos ? mousePos->_y : 0.f; -} - -float GetMouseWorldZ() { - PVECTOR3 mousePos = GetMouseWorldPos(); - - return mousePos ? mousePos->_z : 0.f; -} - -PVECTOR3 GetEffectPos(UINT object) { - return GetObjectPos(object); -} - -float GetEffectX(UINT object) { - return GetObjectX(object); -} - -float GetEffectY(UINT object) { - return GetObjectY(object); -} - -float GetEffectZ(UINT object) { - return GetObjectZ(object); -} - -void SetEffectPos(UINT object, const VECTOR3& pos) { - SetObjectPos(object, pos); -} - -void SetEffectX(UINT object, float x) { - SetObjectX(object, x); -} - -void SetEffectY(UINT object, float y) { - SetObjectY(object, y); -} - -void SetEffectZ(UINT object, float z) { - SetObjectZ(object, z); -} - -//------------------------------------------------------------------------ - -void MemHack_reset() { - stringPool.clear(); -} \ No newline at end of file diff --git a/Src/MemHack.h b/Src/MemHack.h deleted file mode 100644 index 7014306..0000000 --- a/Src/MemHack.h +++ /dev/null @@ -1,65 +0,0 @@ -#pragma once - -#include -#include -#include - -#ifndef _MemHack_h_ -#define _MemHack_h_ -typedef struct VECTOR3 { - VECTOR3(float x, float y, float z) : _x(x), _y(y), _z(z) {} - VECTOR3& operator=(const VECTOR3& from) { - if (this == &from) { - return *this; - } - - this->_x = from._x; - this->_y = from._y; - this->_z = from._z; - - return *this; - } - float _x; - float _y; - float _z; -} *PVECTOR3, * LPVECTOR3; -#endif - -void printChat(LPCSTR text, float duration); -void printfChat(float duration, LPCSTR format, ...); - -float GetUnitArmor(UINT unit); -void SetUnitArmor(UINT unit, float armorValue); -float GetUnitMaxLife(UINT unit); -void SetUnitMaxLife(UINT unit, float hp); -float GetUnitMaxMana(UINT unit); -void SetUnitMaxMana(UINT unit, float mana); -float GetUnitLifeRegen(UINT unit); -void SetUnitLifeRegen(UINT unit, float lifeRegen); -float GetUnitManaRegen(UINT unit); -void SetUnitManaRegen(UINT unit, float manaRegen); -UINT GetUnitBaseDamage(UINT unit); -void SetUnitBaseDamage(UINT unit, UINT damage); -float GetUnitAttackSpeed(UINT unit); -void SetUnitAttackSpeed(UINT unit, float speed); -BOOL UnitResetAttackCooldown(UINT unit); -LPCSTR GetItemBaseNameById(UINT itemId); -void SetItemBaseNameById(UINT itemId, LPCSTR name); -LPCSTR GetItemBaseUbertipById(UINT itemId); -void SetItemBaseUbertipById(UINT itemId, LPCSTR ubertip); -LPCSTR GetItemBaseIconPathById(UINT itemId); -void SetItemBaseIconPathById(UINT itemId, LPCSTR path); -PVECTOR3 GetMouseWorldPos(); -float GetMouseWorldX(); -float GetMouseWorldY(); -float GetMouseWorldZ(); -PVECTOR3 GetEffectPos(UINT object); -float GetEffectX(UINT object); -float GetEffectY(UINT object); -float GetEffectZ(UINT object); -void SetEffectPos(UINT object, const VECTOR3& pos); -void SetEffectX(UINT object, float x); -void SetEffectY(UINT object, float y); -void SetEffectZ(UINT object, float z); - -void MemHack_reset(); \ No newline at end of file diff --git a/Src/Utils.cpp b/Src/Utils.cpp deleted file mode 100644 index c6af210..0000000 --- a/Src/Utils.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include "Utils.h" -#include "Global.h" -#include - -std::string cp1251_to_utf8(LPCSTR string) { - std::string retval; - - if (string) { - int usize = MultiByteToWideChar(1251, 0, string, -1, 0, 0), csize; - - if (usize) { - wchar_t* ustring = new wchar_t[usize]; - if (MultiByteToWideChar(1251, 0, string, -1, ustring, usize)) { - csize = WideCharToMultiByte(CP_UTF8, 0, ustring, -1, 0, 0, 0, 0); - if (csize) { - char* cstring = new char[csize]; - if (WideCharToMultiByte(CP_UTF8, 0, ustring, -1, cstring, csize, 0, 0)) { - retval = cstring; - } - - delete[] cstring; - } - } - - delete[] ustring; - } - } - - return retval; -} - -std::string utf8_to_cp1251(LPCSTR string) { - std::string retval; - - if (string) { - int usize = MultiByteToWideChar(CP_UTF8, 0, string, -1, 0, 0), csize; - - if (usize) { - wchar_t* ustring = new wchar_t[usize]; - if (MultiByteToWideChar(CP_UTF8, 0, string, -1, ustring, usize)) { - csize = WideCharToMultiByte(1251, 0, ustring, -1, 0, 0, 0, 0); - if (csize) { - char* cstring = new char[csize]; - if (WideCharToMultiByte(1251, 0, ustring, -1, cstring, csize, 0, 0)) { - retval = cstring; - } - - delete[] cstring; - } - } - - delete[] ustring; - } - } - - return retval; -} - -bool openConsole(LPCSTR title) { - FILE* console; - - bool result = AllocConsole() && !freopen_s(&console, "CONOUT$", "w", stdout); - - SetConsoleTitle(title); - SetConsoleCP(1251); - SetConsoleOutputCP(1251); - - return result; -} - -void clearConsole() { - HANDLE hStdOut; - CONSOLE_SCREEN_BUFFER_INFO csbi; - DWORD count; - DWORD cellCount; - COORD homeCoords = { 0, 0 }; - - hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); - - if (hStdOut == INVALID_HANDLE_VALUE) { - return; - } - - if (!GetConsoleScreenBufferInfo(hStdOut, &csbi)) { - return; - } - - cellCount = csbi.dwSize.X * csbi.dwSize.Y; - - if (!FillConsoleOutputCharacter(hStdOut, ' ', cellCount, homeCoords, &count)) { - return; - } - - if (!FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, cellCount, homeCoords, &count)) { - return; - } - - SetConsoleCursorPosition(hStdOut, homeCoords); -} \ No newline at end of file diff --git a/Src/Utils.h b/Src/Utils.h deleted file mode 100644 index 974324f..0000000 --- a/Src/Utils.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include -#include - -std::string utf8_to_cp1251(LPCSTR string); - -std::string cp1251_to_utf8(LPCSTR string); - -bool openConsole(LPCSTR title); - -void clearConsole(); \ No newline at end of file diff --git a/Src/Warcraft.cpp b/Src/Warcraft.cpp index 4df2f36..39603f7 100644 --- a/Src/Warcraft.cpp +++ b/Src/Warcraft.cpp @@ -1,20 +1,31 @@ +#include "pch.h" #include "Warcraft.h" -#include "Global.h" +#include "fp_call.h" -auto getInstanceTrue = (HANDLE(__fastcall*)(UINT))((UINT_PTR)gameBase + 0x4c34d0); +auto GetInstanceTrue = (HANDLE(__fastcall*)(UINT))((std::ptrdiff_t)gameBase + 0x4c34d0); +UINT pGameState = (std::ptrdiff_t)gameBase + 0xab65f4; +UINT pGameClass2 = (std::ptrdiff_t)gameBase + 0xab4f80; -PJASS_INSTANCE getJassMachine(UINT index) { - UINT_PTR jass_thread = *(UINT_PTR*)(*(UINT_PTR*)((UINT_PTR)getInstance(5) + 0x90) + index * 4); - - return jass_thread ? (PJASS_INSTANCE)jass_thread : NULL; +void PrintChat(LPCSTR text, float duration) { + fast_call((std::ptrdiff_t)gameBase + 0x2f8e40, *(UINT*)pGameClass2, NULL, 0, 0, text, *(UINT*)&duration, 0xFFFFFFFF); + //((void(__fastcall*)(UINT, UINT, UINT, UINT, LPCSTR, UINT, UINT))((UINT)gameBase + 0x2f8e40))(*(UINT*)pGameClass2, NULL, 0, 0, text, *(UINT*)&duration, 0xFFFFFFFF); } -PJASS_INSTANCE getJassInstance() { - HANDLE instance = getInstance(5); +void PrintfChat(float duration, LPCSTR format, ...) { + char text[8192] = { NULL }; + + va_list args; + va_start(args, format); + vsprintf_s(text, format, args); + va_end(args); + + PrintChat(text, duration); +} - return *(UINT_PTR*)((UINT_PTR)instance + 0x14) ? *(PJASS_INSTANCE*)(*(UINT_PTR*)((UINT_PTR)instance + 0xc) + *(UINT_PTR*)((UINT_PTR)instance + 0x14) * 4 - 4) : NULL; +HANDLE GetInstance(UINT index) { + return GetInstanceTrue(index); } -HANDLE getInstance(UINT index) { - return getInstanceTrue(index); +LPVOID ConvertHandle(UINT handle) { + return handle ? *(LPVOID*)(*(UINT*)(*(UINT*)(*(UINT*)pGameState + 0x1c) + 0x19c) + handle * 0xc - 0x2fffff * 4) : NULL; } \ No newline at end of file diff --git a/Src/Warcraft.h b/Src/Warcraft.h index 23d9463..6ae3866 100644 --- a/Src/Warcraft.h +++ b/Src/Warcraft.h @@ -1,68 +1,6 @@ #pragma once -#include - -#ifndef _Warcraft_h -#define _Warcraft_h -typedef struct { - DWORD unk; - size_t max_size; - UINT_PTR array; - - DWORD get(UINT index) { - DWORD result = 0; - - if (index < max_size) { - result = array + 0x10 * index; - ++*(DWORD*)(result + 0xC); - } - - return result; - } - -} STRING_TABLE, * PSTRING_TABLE; - -typedef struct { - BYTE unk[4]; - size_t counter; - DWORD* codes; // max_size = 1024 - - size_t push_code(DWORD address) { - codes[counter] = address; - - return counter++; - } - - size_t size() { - return counter; - } -} CODE_TABLE, * PCODE_TABLE; - -typedef struct { - BYTE rettype; - BYTE type; - BYTE reg; - BYTE opcode; - DWORD value; -} JASS_OPCODE, * PJASS_OPCODE; - -typedef struct { - BYTE unk0[0x20]; - PJASS_OPCODE opcode; - BYTE unk1[0x10]; - UINT has_sleep; - BYTE unk2[0x2818]; - size_t index; - BYTE unk3[0x20]; - PSTRING_TABLE string_table; - BYTE unk4[0x10]; - PCODE_TABLE code_table; - BYTE unk5[0x1C]; -} JASS_INSTANCE, * PJASS_INSTANCE; -#endif - -PJASS_INSTANCE getJassMachine(UINT index = 1); - -PJASS_INSTANCE getJassInstance(); - -HANDLE getInstance(UINT index); \ No newline at end of file +void PrintChat(LPCSTR text, float duration); +void PrintfChat(float duration, LPCSTR format, ...); +HANDLE GetInstance(UINT index); +LPVOID ConvertHandle(UINT handle); \ No newline at end of file diff --git a/Src/fp_call.h b/Src/fp_call.h new file mode 100644 index 0000000..d66ee4b --- /dev/null +++ b/Src/fp_call.h @@ -0,0 +1,77 @@ +#pragma once + +#include + +namespace call_ +{ + template + struct same_size + { + static const bool value = + (!std::is_reference::value && sizeof(OutputClass) == sizeof(InputClass)) + || (std::is_reference::value && sizeof(OutputClass) == sizeof(std::add_pointer::type)); + }; + + template + union cast_union + { + OutputClass out; + InputClass in; + }; + + template + inline uintptr_t cast(const Argument input, typename std::enable_if::type>::value, void>::type* = 0) + { + cast_union u; + static_assert(std::is_trivial::value, "Argument is not a pod."); + static_assert((sizeof(Argument) == sizeof(u)) && (sizeof(Argument) == sizeof(uintptr_t)), "Argument and uintptr_t are not the same size."); + u.in = input; + return u.out; + } + + template + inline uintptr_t cast(const Argument input, typename std::enable_if::type>::value && same_size::value, void>::type* = 0) + { + cast_union u; + static_assert(std::is_trivial::value, "Argument is not a pod."); + u.in = input; + return u.out; + } + + template + inline uintptr_t cast(const Argument input, typename std::enable_if::type>::value && !same_size::value, void>::type* = 0) + { + static_assert(std::is_trivial::value, "Argument is not a pod."); + static_assert(sizeof(Argument) < sizeof(uintptr_t), "Argument can not be converted to uintptr_t."); + return static_cast(input); + } + + template + struct cast_type { + typedef uintptr_t type; + }; +} + +template +inline R std_call(F f, Args ... args) +{ + return (reinterpret_cast::type ... args)>(f))(call_::cast(args)...); +} + +template +inline R fast_call(F f, Args ... args) +{ + return (reinterpret_cast::type ... args)>(f))(call_::cast(args)...); +} + +template +inline R c_call(F f, Args ... args) +{ + return (reinterpret_cast::type ... args)>(f))(call_::cast(args)...); +} + +template +inline R this_call(F f, This t, Args ... args) +{ + return (reinterpret_cast::type, void*, typename call_::cast_type::type ... args)>(f))(call_::cast(t), 0, call_::cast(args)...); +} \ No newline at end of file diff --git a/Src/pch.cpp b/Src/pch.cpp new file mode 100644 index 0000000..1730571 --- /dev/null +++ b/Src/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" \ No newline at end of file diff --git a/Src/Global.h b/Src/pch.h similarity index 56% rename from Src/Global.h rename to Src/pch.h index 6874e71..5cbece3 100644 --- a/Src/Global.h +++ b/Src/pch.h @@ -1,6 +1,17 @@ #pragma once +#ifndef PCH_H +#define PCH_H #include +#include +#include +#include +#include +#include +#include +#include +#include +#include "fp_call.h" #define ANSI_COLOR_RED "\x1B[31m" #define ANSI_COLOR_GREEN "\x1B[32m" @@ -12,8 +23,8 @@ #define WAR3_LUA_MAJOR "1" #define WAR3_LUA_MINOR "1" -#define WAR3_LUA_RELEASE "5" -#define WAR3_LUA_VERSION_NAME ANSI_COLOR_GREEN "Ashenvale" ANSI_COLOR_RESET " - Experimental" +#define WAR3_LUA_RELEASE "6" +#define WAR3_LUA_VERSION_NAME ANSI_COLOR_YELLOW "Outland" ANSI_COLOR_RESET #define WAR3_LUA_VERSION WAR3_LUA_MAJOR "." WAR3_LUA_MINOR "." WAR3_LUA_RELEASE #define WAR3_LUA "War3 Lua " WAR3_LUA_VERSION @@ -21,9 +32,9 @@ #define GAME_ID "W3L" static HMODULE gameBase = GetModuleHandle("game.dll"); -static HWND gameWindow = FindWindow(NULL, "Warcraft III"); +static HANDLE* pMapMpq = (HANDLE*)((std::ptrdiff_t)gameBase + 0xaae788); -static HANDLE* pMapMpq = (HANDLE*)((UINT_PTR)gameBase + 0xaae788); +extern bool developerMode; -extern bool consoleMode; -extern bool developerMode; \ No newline at end of file +extern SYSTEMTIME date; +#endif \ No newline at end of file diff --git a/war3_lua.sln b/war3_lua.sln index 38017d6..aa0cf7f 100644 --- a/war3_lua.sln +++ b/war3_lua.sln @@ -1,22 +1,22 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 -VisualStudioVersion = 17.0.31912.275 +VisualStudioVersion = 17.1.32421.90 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "war3_lua", "war3_lua.vcxproj", "{9E1903DF-815D-4B82-A6DA-E0D40674769A}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "war3_lua", "war3_lua.vcxproj", "{E196008E-BA95-4E1F-9ED5-7CD8F16ED9AF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {9E1903DF-815D-4B82-A6DA-E0D40674769A}.Release|x86.ActiveCfg = Release|Win32 - {9E1903DF-815D-4B82-A6DA-E0D40674769A}.Release|x86.Build.0 = Release|Win32 + {E196008E-BA95-4E1F-9ED5-7CD8F16ED9AF}.Release|x86.ActiveCfg = Release|Win32 + {E196008E-BA95-4E1F-9ED5-7CD8F16ED9AF}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {694AD159-1A6F-454F-892D-0F27114DA170} + SolutionGuid = {F77543EF-A5AC-4550-9B6E-1AC4D70B2836} EndGlobalSection EndGlobal diff --git a/war3_lua.vcxproj b/war3_lua.vcxproj index 5c45558..59b7ddf 100644 --- a/war3_lua.vcxproj +++ b/war3_lua.vcxproj @@ -21,7 +21,7 @@ 16.0 Win32Proj - {9e1903df-815d-4b82-a6da-e0d40674769a} + {e196008e-ba95-4e1f-9ed5-7cd8f16ed9af} war3lua 10.0.19041.0 @@ -29,26 +29,26 @@ DynamicLibrary true - v140 + v141 MultiByte DynamicLibrary false - v140 + v141 true MultiByte DynamicLibrary true - v140 + v141 MultiByte DynamicLibrary false - v140 + v141 true MultiByte @@ -72,27 +72,35 @@ true - $(SolutionDir)Build\bin\ + D:\Warcraft III\ $(SolutionDir)Build\obj\ .mix + $(SolutionDir)3rd\lua;$(SourcePath) + $(SolutionDir)3rd\lua;$(IncludePath) false $(SolutionDir)Build\bin\ $(SolutionDir)Build\obj\ .mix + $(SolutionDir)3rd\lua;$(SourcePath) + $(SolutionDir)3rd\lua;$(IncludePath) true - $(SolutionDir)Build\bin\ + D:\Warcraft III\ $(SolutionDir)Build\obj\ .mix + $(SolutionDir)3rd\lua;$(SourcePath) + $(SolutionDir)3rd\lua;$(IncludePath) false $(SolutionDir)Build\bin\ $(SolutionDir)Build\obj\ .mix + $(SolutionDir)3rd\lua;$(SourcePath) + $(SolutionDir)3rd\lua;$(IncludePath) @@ -100,13 +108,15 @@ true WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)3rd\StormLib\include;$(SolutionDir)3rd\Detours\include;$(SolutionDir)3rd\lua + $(SolutionDir)3rd\Detours\include + Use + pch.h Console - true - $(SolutionDir)3rd\StormLib\Build\bin\Release\Win32;$(SolutionDir)3rd\Detours\lib;%(AdditionalLibraryDirectories) - detours.lib;storm.lib;version.lib;%(AdditionalDependencies) + $(SolutionDir)3rd\Detours\lib + detours.lib;version.lib;%(AdditionalDependencies) + false @@ -117,15 +127,18 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)3rd\StormLib\include;$(SolutionDir)3rd\Detours\include;$(SolutionDir)3rd\lua + $(SolutionDir)3rd\Detours\include + stdcpp17 + Use + pch.h Console true true - true - $(SolutionDir)3rd\StormLib\Build\bin\Release\Win32;$(SolutionDir)3rd\Detours\lib;%(AdditionalLibraryDirectories) - detours.lib;storm.lib;version.lib;%(AdditionalDependencies) + $(SolutionDir)3rd\Detours\lib + detours.lib;version.lib;%(AdditionalDependencies) + false @@ -134,13 +147,15 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)3rd\StormLib\include;$(SolutionDir)3rd\Detours\include;$(SolutionDir)3rd\lua + $(SolutionDir)3rd\Detours\include + Use + pch.h Console - true - $(SolutionDir)3rd\StormLib\Build\bin\Release\Win32;$(SolutionDir)3rd\Detours\lib;%(AdditionalLibraryDirectories) - detours.lib;storm.lib;version.lib;%(AdditionalDependencies) + $(SolutionDir)3rd\Detours\lib + detours.lib;version.lib;%(AdditionalDependencies) + false @@ -151,70 +166,245 @@ true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)3rd\StormLib\include;$(SolutionDir)3rd\Detours\include;$(SolutionDir)3rd\lua + $(SolutionDir)3rd\Detours\include + Use + pch.h Console true true - true - $(SolutionDir)3rd\StormLib\Build\bin\Release\Win32;$(SolutionDir)3rd\Detours\lib;%(AdditionalLibraryDirectories) - detours.lib;storm.lib;version.lib;%(AdditionalDependencies) + $(SolutionDir)3rd\Detours\lib + detours.lib;version.lib;%(AdditionalDependencies) + false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + NotUsing + NotUsing + NotUsing + NotUsing + + + + + ../pch.h + ../pch.h + ../pch.h + ../pch.h + + - - - + + Create + Create + Create + Create + @@ -246,16 +436,18 @@ - - + + + + + - - + diff --git a/war3_lua.vcxproj.filters b/war3_lua.vcxproj.filters index 27f0414..4e41a62 100644 --- a/war3_lua.vcxproj.filters +++ b/war3_lua.vcxproj.filters @@ -15,26 +15,13 @@ - - - - - - - Файлы ресурсов - - - - + Исходные файлы - + Исходные файлы - - Исходные файлы - - + Исходные файлы @@ -43,19 +30,22 @@ Исходные файлы + + Исходные файлы + Исходные файлы Исходные файлы - + Исходные файлы - + Исходные файлы - + Исходные файлы @@ -160,18 +150,15 @@ Исходные файлы + + Исходные файлы + - - Файлы заголовков - - - Файлы заголовков - - + Файлы заголовков - + Файлы заголовков @@ -180,19 +167,28 @@ Файлы заголовков + + Файлы заголовков + Файлы заголовков Файлы заголовков - + + Файлы заголовков + + Файлы заголовков - + Файлы заголовков - + + Файлы заголовков + + Файлы заголовков @@ -279,5 +275,8 @@ Файлы заголовков + + Файлы заголовков + \ No newline at end of file