Skip to content

Commit

Permalink
backup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ev3nt committed Dec 25, 2021
1 parent 1c1d614 commit 5c10abb
Show file tree
Hide file tree
Showing 10 changed files with 489 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# War3 Lua - 1.1.3 (Beta)
# War3 Lua - 1.1.4 (Beta)

[![build](https://github.com/Ev3nt/war3_lua/actions/workflows/build.yml/badge.svg)](https://github.com/Ev3nt/war3_lua/actions/workflows/build.yml)

Expand Down
23 changes: 22 additions & 1 deletion Src/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,28 @@
#include "Variables.h"
#include "Mem.h"
#include "LuaMachine.h"
#include <Storm.h>

DWORD __fastcall jassEntryPoint(DWORD a) {
return (fastcall<DWORD>(MakePtr(gameBase, _jassEntryPointProc), a), startLua());
}
}

DWORD __stdcall getWarcraftID()
{
return *(DWORD*)GAME_ID;
}

//BOOL __fastcall glueButtonOnClick(UINT frame, UINT, BOOL unknown1) {
// if (thiscall<bool>(MakePtr(gameBase, 0x62a580), frame, 0x40090064)) {
// *(DWORD*)MakePtr(gameBase, 0xa9a7c4) = unknown1;
// *(DWORD*)MakePtr(gameBase, 0xa9a7c8) = frame;
// *(DWORD*)MakePtr(gameBase, 0xa9a7bc) = 0x40090064;
//
// return thiscall<BOOL>(*(DWORD*)(*(DWORD*)frame + 0x10), frame, MakePtr(gameBase, 0xa9a7b4));
// }
// else {
// Beep(500, 200);
// }
//
// return FALSE;
//}
6 changes: 5 additions & 1 deletion Src/Hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

#include <Windows.h>

DWORD __fastcall jassEntryPoint(DWORD a);
DWORD __fastcall jassEntryPoint(DWORD a);

DWORD __stdcall getWarcraftID();

//BOOL __fastcall glueButtonOnClick(UINT frame, UINT, BOOL unknown1);
2 changes: 1 addition & 1 deletion Src/JassMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ DWORD _declspec(naked) jassOpcodeStartLuaThread() {
ret
}
}

// game.dll + 45969d
void jassOpcodeInitialize() {
DWORD overflow = MakePtr(gameBase, _overflowOpcodeProc);
memcpy(OPCODES_FUNCTIONS, (LPVOID)MakePtr(gameBase, _opcodeList), sizeof(OPCODES_FUNCTIONS));
Expand Down
5 changes: 4 additions & 1 deletion Src/JassMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ typedef struct {
}

DWORD getcode() {
return ((DWORD)&oplist - getJassMachine()->code_table->table) / 4;
//return (DWORD)oplist.data();
//printf("%08X\n", getJassMachine());

return ((DWORD)&oplist - (DWORD)getJassMachine()->code_table->codes) / 4;
}

} JASS_OPLIST, * PJASS_OPLIST;
Expand Down
158 changes: 158 additions & 0 deletions Src/LuaRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "JassNatives.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));
Expand Down Expand Up @@ -106,6 +107,8 @@ LUA lua_jCall(lua_State* l) {
return native.get_rettype() != TYPE_NOTHING ? 1 : 0;
}

//-------------------------------------------------------------

LUA lua_GetMouseWorldPos(lua_State* l) {
PVECTOR3 mousePos = GetMouseWorldPos();

Expand Down Expand Up @@ -211,6 +214,122 @@ LUA lua_ConvertHandleToObject(lua_State* l) {

//-------------------------------------------------------------

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_CreateFrame(lua_State* l) {
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);
Expand All @@ -234,4 +353,43 @@ void lua_open_warcraftfunctions(lua_State* l) {
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);
}
7 changes: 5 additions & 2 deletions Src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ BOOL APIENTRY DllMain(HMODULE hModule, UINT ul_reason_for_call, LPVOID lpReserve
size_t i;
for (i = strlen(cmdline); i > 0 && cmdline[i] != '\"'; i--);

if (strstr(&cmdline[i + 1], "-debug")) {
if (strstr(&cmdline[i + 1], "-console") || strstr(&cmdline[i + 1], "-debug")) {
FILE* console;
AllocConsole();
freopen_s(&console, "CONOUT$", "w", stdout);
SetConsoleTitle("Lua Debug");
SetConsoleTitle("Lua Console");
}

printf("%s\n%s\n", LUA_COPYRIGHT, WAR3_LUA);
Expand All @@ -29,6 +29,9 @@ BOOL APIENTRY DllMain(HMODULE hModule, UINT ul_reason_for_call, LPVOID lpReserve
jassOpcodeInitialize();

call(MakePtr(gameBase, _jassEntryPoint), jassEntryPoint);
call(MakePtr(gameBase, _getWarcraftID1), getWarcraftID);
call(MakePtr(gameBase, _getWarcraftID2), getWarcraftID);
//call(MakePtr(gameBase, 0x6025d8), glueButtonOnClick);
}
else {
return FALSE;
Expand Down
37 changes: 35 additions & 2 deletions Src/Variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,60 @@

#define WAR3_LUA_MAJOR "1"
#define WAR3_LUA_MINOR "1"
#define WAR3_LUA_RELEASE "3 (Beta)"
#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
_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
};

extern std::map<LPCSTR, JASSNATIVE> jassnatives;
Expand Down
Loading

0 comments on commit 5c10abb

Please sign in to comment.