diff --git a/3rd/Detours/Include/detours.h b/3rd/Detours/Include/detours.h new file mode 100644 index 0000000..fe7acf1 --- /dev/null +++ b/3rd/Detours/Include/detours.h @@ -0,0 +1,1059 @@ +///////////////////////////////////////////////////////////////////////////// +// +// Core Detours Functionality (detours.h of detours.lib) +// +// Microsoft Research Detours Package, Version 4.0.1 +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// + +#pragma once +#ifndef _DETOURS_H_ +#define _DETOURS_H_ + +#define DETOURS_VERSION 0x4c0c1 // 0xMAJORcMINORcPATCH + +////////////////////////////////////////////////////////////////////////////// +// + +#undef DETOURS_X64 +#undef DETOURS_X86 +#undef DETOURS_IA64 +#undef DETOURS_ARM +#undef DETOURS_ARM64 +#undef DETOURS_BITS +#undef DETOURS_32BIT +#undef DETOURS_64BIT + +#if defined(_X86_) +#define DETOURS_X86 +#define DETOURS_OPTION_BITS 64 + +#elif defined(_AMD64_) +#define DETOURS_X64 +#define DETOURS_OPTION_BITS 32 + +#elif defined(_IA64_) +#define DETOURS_IA64 +#define DETOURS_OPTION_BITS 32 + +#elif defined(_ARM_) +#define DETOURS_ARM + +#elif defined(_ARM64_) +#define DETOURS_ARM64 + +#else +#error Unknown architecture (x86, amd64, ia64, arm, arm64) +#endif + +#ifdef _WIN64 +#undef DETOURS_32BIT +#define DETOURS_64BIT 1 +#define DETOURS_BITS 64 +// If all 64bit kernels can run one and only one 32bit architecture. +//#define DETOURS_OPTION_BITS 32 +#else +#define DETOURS_32BIT 1 +#undef DETOURS_64BIT +#define DETOURS_BITS 32 +// If all 64bit kernels can run one and only one 32bit architecture. +//#define DETOURS_OPTION_BITS 32 +#endif + +#define VER_DETOURS_BITS DETOUR_STRINGIFY(DETOURS_BITS) + +////////////////////////////////////////////////////////////////////////////// +// + +#if (_MSC_VER < 1299) +typedef LONG LONG_PTR; +typedef ULONG ULONG_PTR; +#endif + +///////////////////////////////////////////////// SAL 2.0 Annotations w/o SAL. +// +// These definitions are include so that Detours will build even if the +// compiler doesn't have full SAL 2.0 support. +// +#ifndef DETOURS_DONT_REMOVE_SAL_20 + +#ifdef DETOURS_TEST_REMOVE_SAL_20 +#undef _Analysis_assume_ +#undef _Benign_race_begin_ +#undef _Benign_race_end_ +#undef _Field_range_ +#undef _Field_size_ +#undef _In_ +#undef _In_bytecount_ +#undef _In_count_ +#undef _In_opt_ +#undef _In_opt_bytecount_ +#undef _In_opt_count_ +#undef _In_opt_z_ +#undef _In_range_ +#undef _In_reads_ +#undef _In_reads_bytes_ +#undef _In_reads_opt_ +#undef _In_reads_opt_bytes_ +#undef _In_reads_or_z_ +#undef _In_z_ +#undef _Inout_ +#undef _Inout_opt_ +#undef _Inout_z_count_ +#undef _Out_ +#undef _Out_opt_ +#undef _Out_writes_ +#undef _Outptr_result_maybenull_ +#undef _Readable_bytes_ +#undef _Success_ +#undef _Writable_bytes_ +#undef _Pre_notnull_ +#endif + +#if defined(_Deref_out_opt_z_) && !defined(_Outptr_result_maybenull_) +#define _Outptr_result_maybenull_ _Deref_out_opt_z_ +#endif + +#if defined(_In_count_) && !defined(_In_reads_) +#define _In_reads_(x) _In_count_(x) +#endif + +#if defined(_In_opt_count_) && !defined(_In_reads_opt_) +#define _In_reads_opt_(x) _In_opt_count_(x) +#endif + +#if defined(_In_opt_bytecount_) && !defined(_In_reads_opt_bytes_) +#define _In_reads_opt_bytes_(x) _In_opt_bytecount_(x) +#endif + +#if defined(_In_bytecount_) && !defined(_In_reads_bytes_) +#define _In_reads_bytes_(x) _In_bytecount_(x) +#endif + +#ifndef _In_ +#define _In_ +#endif + +#ifndef _In_bytecount_ +#define _In_bytecount_(x) +#endif + +#ifndef _In_count_ +#define _In_count_(x) +#endif + +#ifndef _In_opt_ +#define _In_opt_ +#endif + +#ifndef _In_opt_bytecount_ +#define _In_opt_bytecount_(x) +#endif + +#ifndef _In_opt_count_ +#define _In_opt_count_(x) +#endif + +#ifndef _In_opt_z_ +#define _In_opt_z_ +#endif + +#ifndef _In_range_ +#define _In_range_(x,y) +#endif + +#ifndef _In_reads_ +#define _In_reads_(x) +#endif + +#ifndef _In_reads_bytes_ +#define _In_reads_bytes_(x) +#endif + +#ifndef _In_reads_opt_ +#define _In_reads_opt_(x) +#endif + +#ifndef _In_reads_opt_bytes_ +#define _In_reads_opt_bytes_(x) +#endif + +#ifndef _In_reads_or_z_ +#define _In_reads_or_z_ +#endif + +#ifndef _In_z_ +#define _In_z_ +#endif + +#ifndef _Inout_ +#define _Inout_ +#endif + +#ifndef _Inout_opt_ +#define _Inout_opt_ +#endif + +#ifndef _Inout_z_count_ +#define _Inout_z_count_(x) +#endif + +#ifndef _Out_ +#define _Out_ +#endif + +#ifndef _Out_opt_ +#define _Out_opt_ +#endif + +#ifndef _Out_writes_ +#define _Out_writes_(x) +#endif + +#ifndef _Outptr_result_maybenull_ +#define _Outptr_result_maybenull_ +#endif + +#ifndef _Writable_bytes_ +#define _Writable_bytes_(x) +#endif + +#ifndef _Readable_bytes_ +#define _Readable_bytes_(x) +#endif + +#ifndef _Success_ +#define _Success_(x) +#endif + +#ifndef _Pre_notnull_ +#define _Pre_notnull_ +#endif + +#ifdef DETOURS_INTERNAL + +#pragma warning(disable:4615) // unknown warning type (suppress with older compilers) + +#ifndef _Benign_race_begin_ +#define _Benign_race_begin_ +#endif + +#ifndef _Benign_race_end_ +#define _Benign_race_end_ +#endif + +#ifndef _Field_size_ +#define _Field_size_(x) +#endif + +#ifndef _Field_range_ +#define _Field_range_(x,y) +#endif + +#ifndef _Analysis_assume_ +#define _Analysis_assume_(x) +#endif + +#endif // DETOURS_INTERNAL +#endif // DETOURS_DONT_REMOVE_SAL_20 + +////////////////////////////////////////////////////////////////////////////// +// +#ifndef GUID_DEFINED +#define GUID_DEFINED +typedef struct _GUID +{ + DWORD Data1; + WORD Data2; + WORD Data3; + BYTE Data4[ 8 ]; +} GUID; + +#ifdef INITGUID +#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + const GUID name \ + = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } +#else +#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + const GUID name +#endif // INITGUID +#endif // !GUID_DEFINED + +#if defined(__cplusplus) +#ifndef _REFGUID_DEFINED +#define _REFGUID_DEFINED +#define REFGUID const GUID & +#endif // !_REFGUID_DEFINED +#else // !__cplusplus +#ifndef _REFGUID_DEFINED +#define _REFGUID_DEFINED +#define REFGUID const GUID * const +#endif // !_REFGUID_DEFINED +#endif // !__cplusplus + +#ifndef ARRAYSIZE +#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0])) +#endif + +// +////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +/////////////////////////////////////////////////// Instruction Target Macros. +// +#define DETOUR_INSTRUCTION_TARGET_NONE ((PVOID)0) +#define DETOUR_INSTRUCTION_TARGET_DYNAMIC ((PVOID)(LONG_PTR)-1) +#define DETOUR_SECTION_HEADER_SIGNATURE 0x00727444 // "Dtr\0" + +extern const GUID DETOUR_EXE_RESTORE_GUID; +extern const GUID DETOUR_EXE_HELPER_GUID; + +#define DETOUR_TRAMPOLINE_SIGNATURE 0x21727444 // Dtr! +typedef struct _DETOUR_TRAMPOLINE DETOUR_TRAMPOLINE, *PDETOUR_TRAMPOLINE; + +/////////////////////////////////////////////////////////// Binary Structures. +// +#pragma pack(push, 8) +typedef struct _DETOUR_SECTION_HEADER +{ + DWORD cbHeaderSize; + DWORD nSignature; + DWORD nDataOffset; + DWORD cbDataSize; + + DWORD nOriginalImportVirtualAddress; + DWORD nOriginalImportSize; + DWORD nOriginalBoundImportVirtualAddress; + DWORD nOriginalBoundImportSize; + + DWORD nOriginalIatVirtualAddress; + DWORD nOriginalIatSize; + DWORD nOriginalSizeOfImage; + DWORD cbPrePE; + + DWORD nOriginalClrFlags; + DWORD reserved1; + DWORD reserved2; + DWORD reserved3; + + // Followed by cbPrePE bytes of data. +} DETOUR_SECTION_HEADER, *PDETOUR_SECTION_HEADER; + +typedef struct _DETOUR_SECTION_RECORD +{ + DWORD cbBytes; + DWORD nReserved; + GUID guid; +} DETOUR_SECTION_RECORD, *PDETOUR_SECTION_RECORD; + +typedef struct _DETOUR_CLR_HEADER +{ + // Header versioning + ULONG cb; + USHORT MajorRuntimeVersion; + USHORT MinorRuntimeVersion; + + // Symbol table and startup information + IMAGE_DATA_DIRECTORY MetaData; + ULONG Flags; + + // Followed by the rest of the IMAGE_COR20_HEADER +} DETOUR_CLR_HEADER, *PDETOUR_CLR_HEADER; + +typedef struct _DETOUR_EXE_RESTORE +{ + DWORD cb; + DWORD cbidh; + DWORD cbinh; + DWORD cbclr; + + PBYTE pidh; + PBYTE pinh; + PBYTE pclr; + + IMAGE_DOS_HEADER idh; + union { + IMAGE_NT_HEADERS inh; + IMAGE_NT_HEADERS32 inh32; + IMAGE_NT_HEADERS64 inh64; + BYTE raw[sizeof(IMAGE_NT_HEADERS64) + + sizeof(IMAGE_SECTION_HEADER) * 32]; + }; + DETOUR_CLR_HEADER clr; + +} DETOUR_EXE_RESTORE, *PDETOUR_EXE_RESTORE; + +typedef struct _DETOUR_EXE_HELPER +{ + DWORD cb; + DWORD pid; + DWORD nDlls; + CHAR rDlls[4]; +} DETOUR_EXE_HELPER, *PDETOUR_EXE_HELPER; + +#pragma pack(pop) + +#define DETOUR_SECTION_HEADER_DECLARE(cbSectionSize) \ +{ \ + sizeof(DETOUR_SECTION_HEADER),\ + DETOUR_SECTION_HEADER_SIGNATURE,\ + sizeof(DETOUR_SECTION_HEADER),\ + (cbSectionSize),\ + \ + 0,\ + 0,\ + 0,\ + 0,\ + \ + 0,\ + 0,\ + 0,\ + 0,\ +} + +/////////////////////////////////////////////////////////////// Helper Macros. +// +#define DETOURS_STRINGIFY(x) DETOURS_STRINGIFY_(x) +#define DETOURS_STRINGIFY_(x) #x + +///////////////////////////////////////////////////////////// Binary Typedefs. +// +typedef BOOL (CALLBACK *PF_DETOUR_BINARY_BYWAY_CALLBACK)( + _In_opt_ PVOID pContext, + _In_opt_ LPCSTR pszFile, + _Outptr_result_maybenull_ LPCSTR *ppszOutFile); + +typedef BOOL (CALLBACK *PF_DETOUR_BINARY_FILE_CALLBACK)( + _In_opt_ PVOID pContext, + _In_ LPCSTR pszOrigFile, + _In_ LPCSTR pszFile, + _Outptr_result_maybenull_ LPCSTR *ppszOutFile); + +typedef BOOL (CALLBACK *PF_DETOUR_BINARY_SYMBOL_CALLBACK)( + _In_opt_ PVOID pContext, + _In_ ULONG nOrigOrdinal, + _In_ ULONG nOrdinal, + _Out_ ULONG *pnOutOrdinal, + _In_opt_ LPCSTR pszOrigSymbol, + _In_opt_ LPCSTR pszSymbol, + _Outptr_result_maybenull_ LPCSTR *ppszOutSymbol); + +typedef BOOL (CALLBACK *PF_DETOUR_BINARY_COMMIT_CALLBACK)( + _In_opt_ PVOID pContext); + +typedef BOOL (CALLBACK *PF_DETOUR_ENUMERATE_EXPORT_CALLBACK)(_In_opt_ PVOID pContext, + _In_ ULONG nOrdinal, + _In_opt_ LPCSTR pszName, + _In_opt_ PVOID pCode); + +typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FILE_CALLBACK)(_In_opt_ PVOID pContext, + _In_opt_ HMODULE hModule, + _In_opt_ LPCSTR pszFile); + +typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FUNC_CALLBACK)(_In_opt_ PVOID pContext, + _In_ DWORD nOrdinal, + _In_opt_ LPCSTR pszFunc, + _In_opt_ PVOID pvFunc); + +// Same as PF_DETOUR_IMPORT_FUNC_CALLBACK but extra indirection on last parameter. +typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FUNC_CALLBACK_EX)(_In_opt_ PVOID pContext, + _In_ DWORD nOrdinal, + _In_opt_ LPCSTR pszFunc, + _In_opt_ PVOID* ppvFunc); + +typedef VOID * PDETOUR_BINARY; +typedef VOID * PDETOUR_LOADED_BINARY; + +//////////////////////////////////////////////////////////// Transaction APIs. +// +LONG WINAPI DetourTransactionBegin(VOID); +LONG WINAPI DetourTransactionAbort(VOID); +LONG WINAPI DetourTransactionCommit(VOID); +LONG WINAPI DetourTransactionCommitEx(_Out_opt_ PVOID **pppFailedPointer); + +LONG WINAPI DetourUpdateThread(_In_ HANDLE hThread); + +LONG WINAPI DetourAttach(_Inout_ PVOID *ppPointer, + _In_ PVOID pDetour); + +LONG WINAPI DetourAttachEx(_Inout_ PVOID *ppPointer, + _In_ PVOID pDetour, + _Out_opt_ PDETOUR_TRAMPOLINE *ppRealTrampoline, + _Out_opt_ PVOID *ppRealTarget, + _Out_opt_ PVOID *ppRealDetour); + +LONG WINAPI DetourDetach(_Inout_ PVOID *ppPointer, + _In_ PVOID pDetour); + +BOOL WINAPI DetourSetIgnoreTooSmall(_In_ BOOL fIgnore); +BOOL WINAPI DetourSetRetainRegions(_In_ BOOL fRetain); +PVOID WINAPI DetourSetSystemRegionLowerBound(_In_ PVOID pSystemRegionLowerBound); +PVOID WINAPI DetourSetSystemRegionUpperBound(_In_ PVOID pSystemRegionUpperBound); + +////////////////////////////////////////////////////////////// Code Functions. +// +PVOID WINAPI DetourFindFunction(_In_ LPCSTR pszModule, + _In_ LPCSTR pszFunction); +PVOID WINAPI DetourCodeFromPointer(_In_ PVOID pPointer, + _Out_opt_ PVOID *ppGlobals); +PVOID WINAPI DetourCopyInstruction(_In_opt_ PVOID pDst, + _Inout_opt_ PVOID *ppDstPool, + _In_ PVOID pSrc, + _Out_opt_ PVOID *ppTarget, + _Out_opt_ LONG *plExtra); +BOOL WINAPI DetourSetCodeModule(_In_ HMODULE hModule, + _In_ BOOL fLimitReferencesToModule); + +///////////////////////////////////////////////////// Loaded Binary Functions. +// +HMODULE WINAPI DetourGetContainingModule(_In_ PVOID pvAddr); +HMODULE WINAPI DetourEnumerateModules(_In_opt_ HMODULE hModuleLast); +PVOID WINAPI DetourGetEntryPoint(_In_opt_ HMODULE hModule); +ULONG WINAPI DetourGetModuleSize(_In_opt_ HMODULE hModule); +BOOL WINAPI DetourEnumerateExports(_In_ HMODULE hModule, + _In_opt_ PVOID pContext, + _In_ PF_DETOUR_ENUMERATE_EXPORT_CALLBACK pfExport); +BOOL WINAPI DetourEnumerateImports(_In_opt_ HMODULE hModule, + _In_opt_ PVOID pContext, + _In_opt_ PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile, + _In_opt_ PF_DETOUR_IMPORT_FUNC_CALLBACK pfImportFunc); + +BOOL WINAPI DetourEnumerateImportsEx(_In_opt_ HMODULE hModule, + _In_opt_ PVOID pContext, + _In_opt_ PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile, + _In_opt_ PF_DETOUR_IMPORT_FUNC_CALLBACK_EX pfImportFuncEx); + +_Writable_bytes_(*pcbData) +_Readable_bytes_(*pcbData) +_Success_(return != NULL) +PVOID WINAPI DetourFindPayload(_In_opt_ HMODULE hModule, + _In_ REFGUID rguid, + _Out_ DWORD *pcbData); + +_Writable_bytes_(*pcbData) +_Readable_bytes_(*pcbData) +_Success_(return != NULL) +PVOID WINAPI DetourFindPayloadEx(_In_ REFGUID rguid, + _Out_ DWORD * pcbData); + +DWORD WINAPI DetourGetSizeOfPayloads(_In_opt_ HMODULE hModule); + +///////////////////////////////////////////////// Persistent Binary Functions. +// + +PDETOUR_BINARY WINAPI DetourBinaryOpen(_In_ HANDLE hFile); + +_Writable_bytes_(*pcbData) +_Readable_bytes_(*pcbData) +_Success_(return != NULL) +PVOID WINAPI DetourBinaryEnumeratePayloads(_In_ PDETOUR_BINARY pBinary, + _Out_opt_ GUID *pGuid, + _Out_ DWORD *pcbData, + _Inout_ DWORD *pnIterator); + +_Writable_bytes_(*pcbData) +_Readable_bytes_(*pcbData) +_Success_(return != NULL) +PVOID WINAPI DetourBinaryFindPayload(_In_ PDETOUR_BINARY pBinary, + _In_ REFGUID rguid, + _Out_ DWORD *pcbData); + +PVOID WINAPI DetourBinarySetPayload(_In_ PDETOUR_BINARY pBinary, + _In_ REFGUID rguid, + _In_reads_opt_(cbData) PVOID pData, + _In_ DWORD cbData); +BOOL WINAPI DetourBinaryDeletePayload(_In_ PDETOUR_BINARY pBinary, _In_ REFGUID rguid); +BOOL WINAPI DetourBinaryPurgePayloads(_In_ PDETOUR_BINARY pBinary); +BOOL WINAPI DetourBinaryResetImports(_In_ PDETOUR_BINARY pBinary); +BOOL WINAPI DetourBinaryEditImports(_In_ PDETOUR_BINARY pBinary, + _In_opt_ PVOID pContext, + _In_opt_ PF_DETOUR_BINARY_BYWAY_CALLBACK pfByway, + _In_opt_ PF_DETOUR_BINARY_FILE_CALLBACK pfFile, + _In_opt_ PF_DETOUR_BINARY_SYMBOL_CALLBACK pfSymbol, + _In_opt_ PF_DETOUR_BINARY_COMMIT_CALLBACK pfCommit); +BOOL WINAPI DetourBinaryWrite(_In_ PDETOUR_BINARY pBinary, _In_ HANDLE hFile); +BOOL WINAPI DetourBinaryClose(_In_ PDETOUR_BINARY pBinary); + +/////////////////////////////////////////////////// Create Process & Load Dll. +// +typedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEA)( + _In_opt_ LPCSTR lpApplicationName, + _Inout_opt_ LPSTR lpCommandLine, + _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, + _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, + _In_ BOOL bInheritHandles, + _In_ DWORD dwCreationFlags, + _In_opt_ LPVOID lpEnvironment, + _In_opt_ LPCSTR lpCurrentDirectory, + _In_ LPSTARTUPINFOA lpStartupInfo, + _Out_ LPPROCESS_INFORMATION lpProcessInformation); + +typedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEW)( + _In_opt_ LPCWSTR lpApplicationName, + _Inout_opt_ LPWSTR lpCommandLine, + _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, + _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, + _In_ BOOL bInheritHandles, + _In_ DWORD dwCreationFlags, + _In_opt_ LPVOID lpEnvironment, + _In_opt_ LPCWSTR lpCurrentDirectory, + _In_ LPSTARTUPINFOW lpStartupInfo, + _Out_ LPPROCESS_INFORMATION lpProcessInformation); + +BOOL WINAPI DetourCreateProcessWithDllA(_In_opt_ LPCSTR lpApplicationName, + _Inout_opt_ LPSTR lpCommandLine, + _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, + _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, + _In_ BOOL bInheritHandles, + _In_ DWORD dwCreationFlags, + _In_opt_ LPVOID lpEnvironment, + _In_opt_ LPCSTR lpCurrentDirectory, + _In_ LPSTARTUPINFOA lpStartupInfo, + _Out_ LPPROCESS_INFORMATION lpProcessInformation, + _In_ LPCSTR lpDllName, + _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); + +BOOL WINAPI DetourCreateProcessWithDllW(_In_opt_ LPCWSTR lpApplicationName, + _Inout_opt_ LPWSTR lpCommandLine, + _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, + _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, + _In_ BOOL bInheritHandles, + _In_ DWORD dwCreationFlags, + _In_opt_ LPVOID lpEnvironment, + _In_opt_ LPCWSTR lpCurrentDirectory, + _In_ LPSTARTUPINFOW lpStartupInfo, + _Out_ LPPROCESS_INFORMATION lpProcessInformation, + _In_ LPCSTR lpDllName, + _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); + +#ifdef UNICODE +#define DetourCreateProcessWithDll DetourCreateProcessWithDllW +#define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEW +#else +#define DetourCreateProcessWithDll DetourCreateProcessWithDllA +#define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEA +#endif // !UNICODE + +BOOL WINAPI DetourCreateProcessWithDllExA(_In_opt_ LPCSTR lpApplicationName, + _Inout_opt_ LPSTR lpCommandLine, + _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, + _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, + _In_ BOOL bInheritHandles, + _In_ DWORD dwCreationFlags, + _In_opt_ LPVOID lpEnvironment, + _In_opt_ LPCSTR lpCurrentDirectory, + _In_ LPSTARTUPINFOA lpStartupInfo, + _Out_ LPPROCESS_INFORMATION lpProcessInformation, + _In_ LPCSTR lpDllName, + _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); + +BOOL WINAPI DetourCreateProcessWithDllExW(_In_opt_ LPCWSTR lpApplicationName, + _Inout_opt_ LPWSTR lpCommandLine, + _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, + _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, + _In_ BOOL bInheritHandles, + _In_ DWORD dwCreationFlags, + _In_opt_ LPVOID lpEnvironment, + _In_opt_ LPCWSTR lpCurrentDirectory, + _In_ LPSTARTUPINFOW lpStartupInfo, + _Out_ LPPROCESS_INFORMATION lpProcessInformation, + _In_ LPCSTR lpDllName, + _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); + +#ifdef UNICODE +#define DetourCreateProcessWithDllEx DetourCreateProcessWithDllExW +#else +#define DetourCreateProcessWithDllEx DetourCreateProcessWithDllExA +#endif // !UNICODE + +BOOL WINAPI DetourCreateProcessWithDllsA(_In_opt_ LPCSTR lpApplicationName, + _Inout_opt_ LPSTR lpCommandLine, + _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, + _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, + _In_ BOOL bInheritHandles, + _In_ DWORD dwCreationFlags, + _In_opt_ LPVOID lpEnvironment, + _In_opt_ LPCSTR lpCurrentDirectory, + _In_ LPSTARTUPINFOA lpStartupInfo, + _Out_ LPPROCESS_INFORMATION lpProcessInformation, + _In_ DWORD nDlls, + _In_reads_(nDlls) LPCSTR *rlpDlls, + _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); + +BOOL WINAPI DetourCreateProcessWithDllsW(_In_opt_ LPCWSTR lpApplicationName, + _Inout_opt_ LPWSTR lpCommandLine, + _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, + _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, + _In_ BOOL bInheritHandles, + _In_ DWORD dwCreationFlags, + _In_opt_ LPVOID lpEnvironment, + _In_opt_ LPCWSTR lpCurrentDirectory, + _In_ LPSTARTUPINFOW lpStartupInfo, + _Out_ LPPROCESS_INFORMATION lpProcessInformation, + _In_ DWORD nDlls, + _In_reads_(nDlls) LPCSTR *rlpDlls, + _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); + +#ifdef UNICODE +#define DetourCreateProcessWithDlls DetourCreateProcessWithDllsW +#else +#define DetourCreateProcessWithDlls DetourCreateProcessWithDllsA +#endif // !UNICODE + +BOOL WINAPI DetourProcessViaHelperA(_In_ DWORD dwTargetPid, + _In_ LPCSTR lpDllName, + _In_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); + +BOOL WINAPI DetourProcessViaHelperW(_In_ DWORD dwTargetPid, + _In_ LPCSTR lpDllName, + _In_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); + +#ifdef UNICODE +#define DetourProcessViaHelper DetourProcessViaHelperW +#else +#define DetourProcessViaHelper DetourProcessViaHelperA +#endif // !UNICODE + +BOOL WINAPI DetourProcessViaHelperDllsA(_In_ DWORD dwTargetPid, + _In_ DWORD nDlls, + _In_reads_(nDlls) LPCSTR *rlpDlls, + _In_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); + +BOOL WINAPI DetourProcessViaHelperDllsW(_In_ DWORD dwTargetPid, + _In_ DWORD nDlls, + _In_reads_(nDlls) LPCSTR *rlpDlls, + _In_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); + +#ifdef UNICODE +#define DetourProcessViaHelperDlls DetourProcessViaHelperDllsW +#else +#define DetourProcessViaHelperDlls DetourProcessViaHelperDllsA +#endif // !UNICODE + +BOOL WINAPI DetourUpdateProcessWithDll(_In_ HANDLE hProcess, + _In_reads_(nDlls) LPCSTR *rlpDlls, + _In_ DWORD nDlls); + +BOOL WINAPI DetourUpdateProcessWithDllEx(_In_ HANDLE hProcess, + _In_ HMODULE hImage, + _In_ BOOL bIs32Bit, + _In_reads_(nDlls) LPCSTR *rlpDlls, + _In_ DWORD nDlls); + +BOOL WINAPI DetourCopyPayloadToProcess(_In_ HANDLE hProcess, + _In_ REFGUID rguid, + _In_reads_bytes_(cbData) PVOID pvData, + _In_ DWORD cbData); +BOOL WINAPI DetourRestoreAfterWith(VOID); +BOOL WINAPI DetourRestoreAfterWithEx(_In_reads_bytes_(cbData) PVOID pvData, + _In_ DWORD cbData); +BOOL WINAPI DetourIsHelperProcess(VOID); +VOID CALLBACK DetourFinishHelperProcess(_In_ HWND, + _In_ HINSTANCE, + _In_ LPSTR, + _In_ INT); + +// +////////////////////////////////////////////////////////////////////////////// +#ifdef __cplusplus +} +#endif // __cplusplus + +//////////////////////////////////////////////// Detours Internal Definitions. +// +#ifdef __cplusplus +#ifdef DETOURS_INTERNAL + +#define NOTHROW +// #define NOTHROW (nothrow) + +////////////////////////////////////////////////////////////////////////////// +// +#if (_MSC_VER < 1299) +#include +typedef IMAGEHLP_MODULE IMAGEHLP_MODULE64; +typedef PIMAGEHLP_MODULE PIMAGEHLP_MODULE64; +typedef IMAGEHLP_SYMBOL SYMBOL_INFO; +typedef PIMAGEHLP_SYMBOL PSYMBOL_INFO; + +static inline +LONG InterlockedCompareExchange(_Inout_ LONG *ptr, _In_ LONG nval, _In_ LONG oval) +{ + return (LONG)::InterlockedCompareExchange((PVOID*)ptr, (PVOID)nval, (PVOID)oval); +} +#else +#pragma warning(push) +#pragma warning(disable:4091) // empty typedef +#include +#pragma warning(pop) +#endif + +#ifdef IMAGEAPI // defined by DBGHELP.H +typedef LPAPI_VERSION (NTAPI *PF_ImagehlpApiVersionEx)(_In_ LPAPI_VERSION AppVersion); + +typedef BOOL (NTAPI *PF_SymInitialize)(_In_ HANDLE hProcess, + _In_opt_ LPCSTR UserSearchPath, + _In_ BOOL fInvadeProcess); +typedef DWORD (NTAPI *PF_SymSetOptions)(_In_ DWORD SymOptions); +typedef DWORD (NTAPI *PF_SymGetOptions)(VOID); +typedef DWORD64 (NTAPI *PF_SymLoadModule64)(_In_ HANDLE hProcess, + _In_opt_ HANDLE hFile, + _In_ LPSTR ImageName, + _In_opt_ LPSTR ModuleName, + _In_ DWORD64 BaseOfDll, + _In_opt_ DWORD SizeOfDll); +typedef BOOL (NTAPI *PF_SymGetModuleInfo64)(_In_ HANDLE hProcess, + _In_ DWORD64 qwAddr, + _Out_ PIMAGEHLP_MODULE64 ModuleInfo); +typedef BOOL (NTAPI *PF_SymFromName)(_In_ HANDLE hProcess, + _In_ LPSTR Name, + _Out_ PSYMBOL_INFO Symbol); + +typedef struct _DETOUR_SYM_INFO +{ + HANDLE hProcess; + HMODULE hDbgHelp; + PF_ImagehlpApiVersionEx pfImagehlpApiVersionEx; + PF_SymInitialize pfSymInitialize; + PF_SymSetOptions pfSymSetOptions; + PF_SymGetOptions pfSymGetOptions; + PF_SymLoadModule64 pfSymLoadModule64; + PF_SymGetModuleInfo64 pfSymGetModuleInfo64; + PF_SymFromName pfSymFromName; +} DETOUR_SYM_INFO, *PDETOUR_SYM_INFO; + +PDETOUR_SYM_INFO DetourLoadImageHlp(VOID); + +#endif // IMAGEAPI + +#if defined(_INC_STDIO) && !defined(_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS) +#error detours.h must be included before stdio.h (or at least define _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS earlier) +#endif +#define _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS 1 + +#ifndef DETOUR_TRACE +#if DETOUR_DEBUG +#define DETOUR_TRACE(x) printf x +#define DETOUR_BREAK() __debugbreak() +#include +#include +#else +#define DETOUR_TRACE(x) +#define DETOUR_BREAK() +#endif +#endif + +#if 1 || defined(DETOURS_IA64) + +// +// IA64 instructions are 41 bits, 3 per bundle, plus 5 bit bundle template => 128 bits per bundle. +// + +#define DETOUR_IA64_INSTRUCTIONS_PER_BUNDLE (3) + +#define DETOUR_IA64_TEMPLATE_OFFSET (0) +#define DETOUR_IA64_TEMPLATE_SIZE (5) + +#define DETOUR_IA64_INSTRUCTION_SIZE (41) +#define DETOUR_IA64_INSTRUCTION0_OFFSET (DETOUR_IA64_TEMPLATE_SIZE) +#define DETOUR_IA64_INSTRUCTION1_OFFSET (DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTION_SIZE) +#define DETOUR_IA64_INSTRUCTION2_OFFSET (DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTION_SIZE + DETOUR_IA64_INSTRUCTION_SIZE) + +C_ASSERT(DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTIONS_PER_BUNDLE * DETOUR_IA64_INSTRUCTION_SIZE == 128); + +__declspec(align(16)) struct DETOUR_IA64_BUNDLE +{ + public: + union + { + BYTE data[16]; + UINT64 wide[2]; + }; + + enum { + A_UNIT = 1u, + I_UNIT = 2u, + M_UNIT = 3u, + B_UNIT = 4u, + F_UNIT = 5u, + L_UNIT = 6u, + X_UNIT = 7u, + }; + struct DETOUR_IA64_METADATA + { + ULONG nTemplate : 8; // Instruction template. + ULONG nUnit0 : 4; // Unit for slot 0 + ULONG nUnit1 : 4; // Unit for slot 1 + ULONG nUnit2 : 4; // Unit for slot 2 + }; + + protected: + static const DETOUR_IA64_METADATA s_rceCopyTable[33]; + + UINT RelocateBundle(_Inout_ DETOUR_IA64_BUNDLE* pDst, _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra) const; + + bool RelocateInstruction(_Inout_ DETOUR_IA64_BUNDLE* pDst, + _In_ BYTE slot, + _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra) const; + + // 120 112 104 96 88 80 72 64 56 48 40 32 24 16 8 0 + // f. e. d. c. b. a. 9. 8. 7. 6. 5. 4. 3. 2. 1. 0. + + // 00 + // f.e. d.c. b.a. 9.8. 7.6. 5.4. 3.2. 1.0. + // 0000 0000 0000 0000 0000 0000 0000 001f : Template [4..0] + // 0000 0000 0000 0000 0000 03ff ffff ffe0 : Zero [ 41.. 5] + // 0000 0000 0000 0000 0000 3c00 0000 0000 : Zero [ 45.. 42] + // 0000 0000 0007 ffff ffff c000 0000 0000 : One [ 82.. 46] + // 0000 0000 0078 0000 0000 0000 0000 0000 : One [ 86.. 83] + // 0fff ffff ff80 0000 0000 0000 0000 0000 : Two [123.. 87] + // f000 0000 0000 0000 0000 0000 0000 0000 : Two [127..124] + BYTE GetTemplate() const; + // Get 4 bit opcodes. + BYTE GetInst0() const; + BYTE GetInst1() const; + BYTE GetInst2() const; + BYTE GetUnit(BYTE slot) const; + BYTE GetUnit0() const; + BYTE GetUnit1() const; + BYTE GetUnit2() const; + // Get 37 bit data. + UINT64 GetData0() const; + UINT64 GetData1() const; + UINT64 GetData2() const; + + // Get/set the full 41 bit instructions. + UINT64 GetInstruction(BYTE slot) const; + UINT64 GetInstruction0() const; + UINT64 GetInstruction1() const; + UINT64 GetInstruction2() const; + void SetInstruction(BYTE slot, UINT64 instruction); + void SetInstruction0(UINT64 instruction); + void SetInstruction1(UINT64 instruction); + void SetInstruction2(UINT64 instruction); + + // Get/set bitfields. + static UINT64 GetBits(UINT64 Value, UINT64 Offset, UINT64 Count); + static UINT64 SetBits(UINT64 Value, UINT64 Offset, UINT64 Count, UINT64 Field); + + // Get specific read-only fields. + static UINT64 GetOpcode(UINT64 instruction); // 4bit opcode + static UINT64 GetX(UINT64 instruction); // 1bit opcode extension + static UINT64 GetX3(UINT64 instruction); // 3bit opcode extension + static UINT64 GetX6(UINT64 instruction); // 6bit opcode extension + + // Get/set specific fields. + static UINT64 GetImm7a(UINT64 instruction); + static UINT64 SetImm7a(UINT64 instruction, UINT64 imm7a); + static UINT64 GetImm13c(UINT64 instruction); + static UINT64 SetImm13c(UINT64 instruction, UINT64 imm13c); + static UINT64 GetSignBit(UINT64 instruction); + static UINT64 SetSignBit(UINT64 instruction, UINT64 signBit); + static UINT64 GetImm20a(UINT64 instruction); + static UINT64 SetImm20a(UINT64 instruction, UINT64 imm20a); + static UINT64 GetImm20b(UINT64 instruction); + static UINT64 SetImm20b(UINT64 instruction, UINT64 imm20b); + + static UINT64 SignExtend(UINT64 Value, UINT64 Offset); + + BOOL IsMovlGp() const; + + VOID SetInst(BYTE Slot, BYTE nInst); + VOID SetInst0(BYTE nInst); + VOID SetInst1(BYTE nInst); + VOID SetInst2(BYTE nInst); + VOID SetData(BYTE Slot, UINT64 nData); + VOID SetData0(UINT64 nData); + VOID SetData1(UINT64 nData); + VOID SetData2(UINT64 nData); + BOOL SetNop(BYTE Slot); + BOOL SetNop0(); + BOOL SetNop1(); + BOOL SetNop2(); + + public: + BOOL IsBrl() const; + VOID SetBrl(); + VOID SetBrl(UINT64 target); + UINT64 GetBrlTarget() const; + VOID SetBrlTarget(UINT64 target); + VOID SetBrlImm(UINT64 imm); + UINT64 GetBrlImm() const; + + UINT64 GetMovlGp() const; + VOID SetMovlGp(UINT64 gp); + + VOID SetStop(); + + UINT Copy(_Out_ DETOUR_IA64_BUNDLE *pDst, _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra = NULL) const; +}; +#endif // DETOURS_IA64 + +#ifdef DETOURS_ARM + +#define DETOURS_PFUNC_TO_PBYTE(p) ((PBYTE)(((ULONG_PTR)(p)) & ~(ULONG_PTR)1)) +#define DETOURS_PBYTE_TO_PFUNC(p) ((PBYTE)(((ULONG_PTR)(p)) | (ULONG_PTR)1)) + +#endif // DETOURS_ARM + +////////////////////////////////////////////////////////////////////////////// + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +#define DETOUR_OFFLINE_LIBRARY(x) \ +PVOID WINAPI DetourCopyInstruction##x(_In_opt_ PVOID pDst, \ + _Inout_opt_ PVOID *ppDstPool, \ + _In_ PVOID pSrc, \ + _Out_opt_ PVOID *ppTarget, \ + _Out_opt_ LONG *plExtra); \ + \ +BOOL WINAPI DetourSetCodeModule##x(_In_ HMODULE hModule, \ + _In_ BOOL fLimitReferencesToModule); \ + +DETOUR_OFFLINE_LIBRARY(X86) +DETOUR_OFFLINE_LIBRARY(X64) +DETOUR_OFFLINE_LIBRARY(ARM) +DETOUR_OFFLINE_LIBRARY(ARM64) +DETOUR_OFFLINE_LIBRARY(IA64) + +#undef DETOUR_OFFLINE_LIBRARY + +////////////////////////////////////////////////////////////////////////////// +// +// Helpers for manipulating page protection. +// + +_Success_(return != FALSE) +BOOL WINAPI DetourVirtualProtectSameExecuteEx(_In_ HANDLE hProcess, + _In_ PVOID pAddress, + _In_ SIZE_T nSize, + _In_ DWORD dwNewProtect, + _Out_ PDWORD pdwOldProtect); + +_Success_(return != FALSE) +BOOL WINAPI DetourVirtualProtectSameExecute(_In_ PVOID pAddress, + _In_ SIZE_T nSize, + _In_ DWORD dwNewProtect, + _Out_ PDWORD pdwOldProtect); +#ifdef __cplusplus +} +#endif // __cplusplus + +////////////////////////////////////////////////////////////////////////////// + +#define MM_ALLOCATION_GRANULARITY 0x10000 + +////////////////////////////////////////////////////////////////////////////// + +#endif // DETOURS_INTERNAL +#endif // __cplusplus + +#endif // _DETOURS_H_ +// +//////////////////////////////////////////////////////////////// End of File. diff --git a/3rd/Detours/Include/detver.h b/3rd/Detours/Include/detver.h new file mode 100644 index 0000000..f0aae9b --- /dev/null +++ b/3rd/Detours/Include/detver.h @@ -0,0 +1,27 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Common version parameters. +// +// Microsoft Research Detours Package, Version 4.0.1 +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// + +#define _USING_V110_SDK71_ 1 +#include "winver.h" +#if 0 +#include +#include +#else +#ifndef DETOURS_STRINGIFY +#define DETOURS_STRINGIFY(x) DETOURS_STRINGIFY_(x) +#define DETOURS_STRINGIFY_(x) #x +#endif + +#define VER_FILEFLAGSMASK 0x3fL +#define VER_FILEFLAGS 0x0L +#define VER_FILEOS 0x00040004L +#define VER_FILETYPE 0x00000002L +#define VER_FILESUBTYPE 0x00000000L +#endif +#define VER_DETOURS_BITS DETOUR_STRINGIFY(DETOURS_BITS) diff --git a/3rd/Detours/Lib/detours.lib b/3rd/Detours/Lib/detours.lib new file mode 100644 index 0000000..741e90c Binary files /dev/null and b/3rd/Detours/Lib/detours.lib differ diff --git a/Maps/lua.w3m b/Maps/lua.w3m index 28b1e55..7e7d1b6 100644 Binary files a/Maps/lua.w3m and b/Maps/lua.w3m differ diff --git a/README.md b/README.md index f337a78..f5765bb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# War3 Lua - 1.1.4 (Beta) +# War3 Lua - 1.1.4 (Ashenvale) [![build](https://github.com/Ev3nt/war3_lua/actions/workflows/build.yml/badge.svg)](https://github.com/Ev3nt/war3_lua/actions/workflows/build.yml) diff --git a/Scripts/blizzard.lua b/Scripts/blizzard.lua index a4c6475..9dde0f9 100644 --- a/Scripts/blizzard.lua +++ b/Scripts/blizzard.lua @@ -10218,35 +10218,46 @@ 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) +-- 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 = "" + + for i,v in ipairs({...}) do + string = string..tostring(v) + end + + print(string) + DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, string) end -- =========================================================================== diff --git a/Src/.vscode/settings.json b/Src Backup/.vscode/settings.json similarity index 100% rename from Src/.vscode/settings.json rename to Src Backup/.vscode/settings.json diff --git a/Src Backup/FrameAPI.cpp b/Src Backup/FrameAPI.cpp new file mode 100644 index 0000000..b99317b --- /dev/null +++ b/Src Backup/FrameAPI.cpp @@ -0,0 +1,158 @@ +#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 new file mode 100644 index 0000000..49effa2 --- /dev/null +++ b/Src Backup/FrameAPI.h @@ -0,0 +1,105 @@ +#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 new file mode 100644 index 0000000..da1cfa1 --- /dev/null +++ b/Src Backup/Hooks.cpp @@ -0,0 +1,58 @@ +#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 new file mode 100644 index 0000000..19103cf --- /dev/null +++ b/Src Backup/Hooks.h @@ -0,0 +1,11 @@ +#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 new file mode 100644 index 0000000..0b11610 --- /dev/null +++ b/Src Backup/JassMachine.cpp @@ -0,0 +1,44 @@ +#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 new file mode 100644 index 0000000..0d2a12b --- /dev/null +++ b/Src Backup/JassMachine.h @@ -0,0 +1,148 @@ +#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 new file mode 100644 index 0000000..95aee39 --- /dev/null +++ b/Src Backup/JassNatives.cpp @@ -0,0 +1,156 @@ +#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 new file mode 100644 index 0000000..7d70df0 --- /dev/null +++ b/Src Backup/JassNatives.h @@ -0,0 +1,189 @@ +#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 new file mode 100644 index 0000000..bccce79 --- /dev/null +++ b/Src Backup/LuaMachine.cpp @@ -0,0 +1,438 @@ +#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 new file mode 100644 index 0000000..30eea9d --- /dev/null +++ b/Src Backup/LuaMachine.h @@ -0,0 +1,28 @@ +#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/LuaRegister.cpp b/Src Backup/LuaRegister.cpp similarity index 97% rename from Src/LuaRegister.cpp rename to Src Backup/LuaRegister.cpp index e11f7b4..328f332 100644 --- a/Src/LuaRegister.cpp +++ b/Src Backup/LuaRegister.cpp @@ -4,6 +4,7 @@ #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)) @@ -232,7 +233,14 @@ LUA lua_GetFrameByName(lua_State* l) { 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; @@ -337,6 +345,8 @@ void lua_open_jassnatives(lua_State* l) { } 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); diff --git a/Src/LuaRegister.h b/Src Backup/LuaRegister.h similarity index 100% rename from Src/LuaRegister.h rename to Src Backup/LuaRegister.h diff --git a/Src Backup/Main.cpp b/Src Backup/Main.cpp new file mode 100644 index 0000000..6ca76a4 --- /dev/null +++ b/Src Backup/Main.cpp @@ -0,0 +1,55 @@ +#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/Mem.h b/Src Backup/Mem.h similarity index 100% rename from Src/Mem.h rename to Src Backup/Mem.h diff --git a/Src/Variables.h b/Src Backup/Variables.h similarity index 83% rename from Src/Variables.h rename to Src Backup/Variables.h index b1820f6..b61c47a 100644 --- a/Src/Variables.h +++ b/Src Backup/Variables.h @@ -2,10 +2,12 @@ #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" @@ -62,8 +64,13 @@ enum OFFSETS { _setCLayoutFrameHeight = 0x605db0, _setCLayoutFrameAbsolutePoint = 0x6061b0, _setCLayoutFrameCageMouse = 0x604fc0, - _setCLayoutFrameAllPoints = 0x6067f0 + _setCLayoutFrameAllPoints = 0x6067f0, + + _frameevent_control_click = 0xa9a86c, + _frameevent_control_mouseenter = 0xa9a84c }; extern std::map jassnatives; -extern std::map triggers; \ No newline at end of file +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 new file mode 100644 index 0000000..6a4856b --- /dev/null +++ b/Src Backup/Warcraft.cpp @@ -0,0 +1,29 @@ +#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 new file mode 100644 index 0000000..be7ebab --- /dev/null +++ b/Src Backup/Warcraft.h @@ -0,0 +1,1345 @@ +#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/WarcraftFunctions.cpp b/Src Backup/WarcraftFunctions.cpp similarity index 100% rename from Src/WarcraftFunctions.cpp rename to Src Backup/WarcraftFunctions.cpp diff --git a/Src/WarcraftFunctions.h b/Src Backup/WarcraftFunctions.h similarity index 100% rename from Src/WarcraftFunctions.h rename to Src Backup/WarcraftFunctions.h diff --git a/Src/fcalls.h b/Src Backup/fcalls.h similarity index 100% rename from Src/fcalls.h rename to Src Backup/fcalls.h diff --git a/Src/GameUI.cpp b/Src/GameUI.cpp new file mode 100644 index 0000000..3053be0 --- /dev/null +++ b/Src/GameUI.cpp @@ -0,0 +1,785 @@ +#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, 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 new file mode 100644 index 0000000..f029b90 --- /dev/null +++ b/Src/GameUI.h @@ -0,0 +1,507 @@ +#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/Global.h b/Src/Global.h new file mode 100644 index 0000000..1be4064 --- /dev/null +++ b/Src/Global.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +#define ANSI_COLOR_RED "\x1B[31m" +#define ANSI_COLOR_GREEN "\x1B[32m" +#define ANSI_COLOR_YELLOW "\x1B[33m" +#define ANSI_COLOR_BLUE "\x1B[34m" +#define ANSI_COLOR_MAGENTA "\x1B[35m" +#define ANSI_COLOR_CYAN "\x1B[36m" +#define ANSI_COLOR_RESET "\x1B[0m" + +#define WAR3_LUA_MAJOR "1" +#define WAR3_LUA_MINOR "1" +#define WAR3_LUA_RELEASE "4" +#define WAR3_LUA_VERSION_NAME ANSI_COLOR_GREEN "Ashenvale" ANSI_COLOR_RESET + +#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" + +static HMODULE gameBase = GetModuleHandle("game.dll"); +static HWND gameWindow = FindWindow(NULL, "Warcraft III"); + +static HANDLE* pMapMpq = (HANDLE*)((UINT_PTR)gameBase + 0xaae788); + +extern bool consoleMode; +extern bool developerMode; \ No newline at end of file diff --git a/Src/Hooks.cpp b/Src/Hooks.cpp index 5ce508b..f953211 100644 --- a/Src/Hooks.cpp +++ b/Src/Hooks.cpp @@ -1,30 +1,138 @@ #include "Hooks.h" - -#include "Variables.h" -#include "Mem.h" #include "LuaMachine.h" -#include +#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); -DWORD __fastcall jassEntryPoint(DWORD a) { - return (fastcall(MakePtr(gameBase, _jassEntryPointProc), a), startLua()); +BOOL __fastcall jassEntryPoint(UINT unknown1) { + return jassEntryPointTrue(unknown1) && startLua(); } DWORD __stdcall getWarcraftID() { - return *(DWORD*)GAME_ID; + return *(DWORD*)GAME_ID; +} + +BOOL __fastcall isFrameHasEventObserver(UINT frame, UINT, UINT eventcode) { + if (frameEventHashTable.find(frame) != frameEventHashTable.end()) { + return TRUE; + } + + UINT table = *(DWORD*)(frame + 8); + + if (!table) { + return FALSE; + } + + 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 = -1; + + if (running) { + result = eventCallback(frame, eventtype, eventaddress); + } + + return result == -1 ? reinterpret_cast(*(DWORD*)(*(DWORD*)frame + 0x14))(frame, NULL, eventtype, eventaddress) : result; +} + +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; + } + + 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 __fastcall BuildHPBars(UINT a1, UINT unused, UINT a2, UINT a3) { + BuildHPBarsTrue(a1, unused, a2, a3); + + UINT_PTR pHPBarFrame = *((UINT_PTR*)a1 + 3); + if (pHPBarFrame) { + *((float*)pHPBarFrame + 22) /= wideScreenMul; + } } -//BOOL __fastcall glueButtonOnClick(UINT frame, UINT, BOOL unknown1) { -// if (thiscall(MakePtr(gameBase, 0x62a580), frame, 0x40090064)) { -// *(DWORD*)MakePtr(gameBase, 0xa9a7c4) = unknown1; -// *(DWORD*)MakePtr(gameBase, 0xa9a7c8) = frame; -// *(DWORD*)MakePtr(gameBase, 0xa9a7bc) = 0x40090064; -// -// return thiscall(*(DWORD*)(*(DWORD*)frame + 0x10), frame, MakePtr(gameBase, 0xa9a7b4)); -// } -// else { -// Beep(500, 200); -// } -// -// return FALSE; -//} \ No newline at end of file +//---------------------------------------------------------------- + +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 38df288..296f7d8 100644 --- a/Src/Hooks.h +++ b/Src/Hooks.h @@ -1,9 +1,7 @@ #pragma once -#include +#include -DWORD __fastcall jassEntryPoint(DWORD a); +void attachHooks(); -DWORD __stdcall getWarcraftID(); - -//BOOL __fastcall glueButtonOnClick(UINT frame, UINT, BOOL unknown1); \ 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 0b11610..07310dc 100644 --- a/Src/JassMachine.cpp +++ b/Src/JassMachine.cpp @@ -1,44 +1,34 @@ #include "JassMachine.h" - -#include "Variables.h" -#include "Mem.h" #include "LuaMachine.h" +#include "Global.h" + +PVOID** ppOpcodeList = (PVOID**)((UINT_PTR)gameBase + 0x45ea5a); +BYTE* pOpcodeListSize = (BYTE*)((UINT_PTR)gameBase + 0x45ea4d); +PVOID opcodeDefaultOut = (PVOID)((UINT_PTR)gameBase + 0x45f79a); -DWORD OPCODES_FUNCTIONS[44]; +PVOID OPCODE_FUNCTIONS[44]; -DWORD _declspec(naked) jassOpcodeStartLuaThread() { +DWORD _declspec(naked) opcodeStartLuaThread() { _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 - + push opcodeDefaultOut 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); + memcpy(OPCODE_FUNCTIONS, *ppOpcodeList, sizeof(OPCODE_FUNCTIONS)); + + 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); + + VirtualProtect(ppOpcodeList, 4, PAGE_EXECUTE_READWRITE, &dwOldProtect); + *ppOpcodeList = OPCODE_FUNCTIONS; + VirtualProtect(ppOpcodeList, 4, dwOldProtect, &dwOldProtect); } \ No newline at end of file diff --git a/Src/JassMachine.h b/Src/JassMachine.h index 0d2a12b..d196d54 100644 --- a/Src/JassMachine.h +++ b/Src/JassMachine.h @@ -2,59 +2,56 @@ #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 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 { +enum OPCODE_VARIABLE_TYPE : UINT { OPCODE_VARIABLE_NOTHING = 0, OPCODE_VARIABLE_UNKNOWN, OPCODE_VARIABLE_NULL, @@ -134,9 +131,6 @@ typedef struct { } DWORD getcode() { - //return (DWORD)oplist.data(); - //printf("%08X\n", getJassMachine()); - return ((DWORD)&oplist - (DWORD)getJassMachine()->code_table->codes) / 4; } diff --git a/Src/JassNatives.cpp b/Src/JassNatives.cpp index e7d946f..aa04cd5 100644 --- a/Src/JassNatives.cpp +++ b/Src/JassNatives.cpp @@ -1,36 +1,10 @@ #include "JassNatives.h" - -#include "Variables.h" -#include "Mem.h" #include "JassMachine.h" +#include "LuaMachine.h" +#include "Global.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(); -} - -//--------------------------------------------------------- - +std::unordered_map jassnatives; +std::unordered_map triggers; #pragma pack(push) #pragma pack(1) @@ -51,54 +25,67 @@ struct asm_register_native_function { return ((push.opcode == 0x68) && (mov_edx.opcode == 0xBA) && (mov_ecx.opcode == 0xB9) && (call.opcode == 0xE8)); } - const char* get_params() { - return (const char*)(push.value); + PCSTR get_params() { + return (PCSTR)(push.value); } - const char* get_name() { - return (const char*)(mov_edx.value); + PCSTR get_name() { + return (PCSTR)(mov_edx.value); } - uintptr_t get_address() { - return (uintptr_t)(mov_ecx.value); + PVOID get_address() { + return (PVOID)(mov_ecx.value); } }; //--------------------------------------------------------- -JASSNATIVE::JASSNATIVE(DWORD address, LPCSTR params) : _address(address) { +UINT to_code(lua_State* l, int index) { + DWORD key = (DWORD)lua_topointer(l, index); + + auto it = triggers.find(key); + + if (it != triggers.end()) { + return (UINT)&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(); +} + +//--------------------------------------------------------- + +JASSNATIVE::JASSNATIVE(LPVOID 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 { + if (*it != ')') { + if (isupper(*it)) { _params.push_back((JASS_TYPE)*it); } } + else { + break; + } } + + _rettype = (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; + return _rettype != TYPE_NONE; } const std::vector& JASSNATIVE::get_params() { @@ -109,47 +96,57 @@ const JASS_TYPE& JASSNATIVE::get_rettype() { return _rettype; } -DWORD JASSNATIVE::get_address() { +PVOID 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; +BOOL JASSNATIVE::call(LPVOID params, size_t size) { + PVOID function_address = _address; + size_t params_size = size * sizeof UINT; + LPVOID esp_ptr; + + BOOL result; _asm { sub esp, params_size mov esp_ptr, esp } - memcpy((LPVOID)esp_ptr, params, params_size); + memcpy(esp_ptr, params, params_size); _asm { - call[func_address] + call [function_address] + mov result, eax + mov esp, esp_ptr add esp, params_size - mov retval, eax } - return retval; + return result; } //--------------------------------------------------------- -JASSNATIVE& get_native(LPCSTR lpName) { - for (auto& e : jassnatives) { - if (!strcmp(e.first, lpName)) { - return e.second; +JASSNATIVE invalid; + +JASSNATIVE& get_native(LPCSTR name) { + for (auto& native : jassnatives) { + if (!strcmp(native.first, name)) { + return native.second; } } - return *(JASSNATIVE*)NULL; + return invalid; } -void jassNativesInitialize() { - for (asm_register_native_function* ptr = (asm_register_native_function*)MakePtr(gameBase, _jassNativesList); ptr->verify(); ptr++) { +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 JassNatives_reset() { + triggers.clear(); } \ No newline at end of file diff --git a/Src/JassNatives.h b/Src/JassNatives.h index 7d70df0..0ead06a 100644 --- a/Src/JassNatives.h +++ b/Src/JassNatives.h @@ -2,114 +2,11 @@ #include #include +#include +#include +#include "JassMachine.h" -#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 { +enum JASS_TYPE : BYTE { TYPE_NONE = 0, TYPE_BOOLEAN = 'B', TYPE_CODE = 'C', @@ -120,40 +17,40 @@ enum JASS_TYPE { TYPE_NOTHING = 'V', }; -inline jReal to_jReal(float fX) { - return *(jReal*)&fX; +inline UINT to_real(float value) { + return *(UINT*)&value; } -inline float from_jReal(jReal val) { - return *(float*)&val; +inline float from_real(UINT value) { + return *(float*)&value; } -inline jString to_jString(LPCSTR lpString) { - UINT32* string = new UINT32[8]; +inline UINT to_string(LPCSTR string) { + UINT* pString = new UINT[8]; - string[2] = (UINT32)&string[0]; - string[7] = (UINT32)&lpString[0]; + pString[2] = (UINT)&pString[0]; + pString[7] = (UINT)&string[0]; - return (jString)string; + return (UINT)pString; } -inline LPCSTR from_jString(jString string) { +inline PCSTR from_string(UINT string) { if (!string) { return NULL; } - string = ((jString*)string)[2]; + string = ((UINT*)string)[2]; if (!string) { return NULL; } - return (LPCSTR)((jString*)string)[7]; + return (PCSTR)((UINT*)string)[7]; } -DWORD to_Code(lua_State* l, int index); +UINT to_code(lua_State* l, int index); -inline jInteger to_ID(LPCSTR lpID) { +inline DWORD to_ID(LPCSTR lpID) { return (lpID[0] << 24) + (lpID[1] << 16) + (lpID[2] << 8) + lpID[3]; } @@ -163,27 +60,30 @@ inline jInteger to_ID(LPCSTR lpID) { #define _JassNatives_h class JASSNATIVE { public: - JASSNATIVE(DWORD address, LPCSTR params); + JASSNATIVE(LPVOID 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(); + PVOID get_address(); - DWORD call(DWORD* params, int size); + BOOL call(LPVOID params, size_t size); private: - DWORD _address; + PVOID _address; std::vector _params; JASS_TYPE _rettype; - bool has_sleep = false; }; #endif //--------------------------------------------------------- -JASSNATIVE& get_native(LPCSTR lpName); +JASSNATIVE& get_native(LPCSTR name); -void jassNativesInitialize(); \ No newline at end of file +void jassNativesParse(); + +void JassNatives_reset(); + +//--------------------------------------------------------- + +extern std::unordered_map jassnatives; \ No newline at end of file diff --git a/Src/LuaFunctions.cpp b/Src/LuaFunctions.cpp new file mode 100644 index 0000000..0ed331f --- /dev/null +++ b/Src/LuaFunctions.cpp @@ -0,0 +1,632 @@ +#include "LuaFunctions.h" +#include "JassNatives.h" +#include "GameUI.h" +#include "Warcraft.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)); + + if (size > lua_gettop(l)) { + return luaL_error(l, "function '%s' must have %d %s", name, size, size > 1 ? "arguments" : "argument"); + } + + return FALSE; +} + +//-------------------------------------------------------- +// JassNatives + +int lua_callNative(lua_State* l) { + LPCSTR name = lua_tostring(l, lua_upvalueindex(1)); + JASSNATIVE native = get_native(name); + + if (!native.is_valid()) { + return 0; + } + + int size = native.get_params().size(); + if (size > lua_gettop(l)) { + return luaL_error(l, "function '%s' must have %d %s", name, size, size > 1 ? "arguments" : "argument"); + } + + 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); + } + + 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: { + 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(lua_tostring(l, i)); + + break; + default: + params[i - 1] = NULL; + + break; + } + + 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_CODE: + case TYPE_HANDLE: + case TYPE_INTEGER: + lua_pushinteger(l, result); + + break; + case TYPE_REAL: + lua_pushnumber(l, from_real(result)); + + break; + case TYPE_STRING: + lua_pushstring(l, from_string(getJassMachine()->string_table->get(result))); + + 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_GetOriginFrame(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + lua_pushinteger(l, 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_pushinteger(l, LoadTOCFile(lua_tostring(l, 1))); + + return 1; +} + +int lua_GetFrameByName(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + lua_pushinteger(l, GetFrameByName(lua_tostring(l, 1), (UINT)lua_tointeger(l, 2))); + + return 1; +} + +int lua_GetFrameParent(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + lua_pushinteger(l, GetFrameParent((UINT)lua_tointeger(l, 1))); + + return 1; +} + +int lua_GetFrameChildrenCount(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + lua_pushinteger(l, GetFrameChildrenCount((UINT)lua_tointeger(l, 1))); + + return 1; +} + +int lua_GetFrameChild(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + lua_pushinteger(l, GetFrameChild((UINT)lua_tointeger(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_tointeger(l, 1), (UINT)lua_tointeger(l, 2), (EFrameEvent)lua_tointeger(l, 3)); + + return 0; +} + +int lua_CreateFrame(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + 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; +} + +int lua_SetFrameText(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + SetFrameText((UINT)lua_tointeger(l, 1), lua_tostring(l, 2)); + + return 0; +} + +int lua_GetFrameText(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + lua_pushstring(l, GetFrameText((UINT)lua_tointeger(l, 1))); + + return 1; +} + +int lua_SetFrameTextColor(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + 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; +} + +int lua_GetFrameTextHeight(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + lua_pushnumber(l, GetFrameTextHeight((UINT)lua_tointeger(l, 1))); + + return 1; +} + +int lua_SetFrameWidth(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + SetFrameWidth((UINT)lua_tointeger(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_tointeger(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_tointeger(l, 1), (float)lua_tonumber(l, 2), (float)lua_tonumber(l, 3)); + + return 0; +} + +int lua_SetFrameScale(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + SetFrameScale((UINT)lua_tointeger(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_tointeger(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_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; +} + +int lua_GetFrameWidth(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + lua_pushnumber(l, GetFrameWidth((UINT)lua_tointeger(l, 1))); + + return 1; +} + +int lua_GetFrameHeight(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + lua_pushnumber(l, GetFrameHeight((UINT)lua_tointeger(l, 1))); + + return 1; +} + +int lua_GetFramePointParent(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + lua_pushinteger(l, GetFramePointParent((UINT)lua_tointeger(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_tointeger(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_tointeger(l, 1), (EFramePoint)lua_tointeger(l, 2))); + + return 1; +} + +int lua_GetFramePointY(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + lua_pushnumber(l, GetFramePointY((UINT)lua_tointeger(l, 1), (EFramePoint)lua_tointeger(l, 2))); + + return 1; +} + +int lua_GetTriggerFrame(lua_State* l) { + lua_pushinteger(l, GetTriggerFrame()); + + return 1; +} + +int lua_GetFrameValue(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + lua_pushnumber(l, GetFrameValue((UINT)lua_tointeger(l, 1))); + + return 1; +} + +int lua_GetTriggerFrameValue(lua_State* l) { + lua_pushnumber(l, GetTriggerFrameValue()); + + return 1; +} + +int lua_SetFrameValue(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + SetFrameValue((UINT)lua_tointeger(l, 1), (float)lua_tonumber(l, 2)); + + return 0; +} + +int lua_SetFrameMinMaxValue(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + SetFrameMinMaxValue((UINT)lua_tointeger(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; + } + + SetFrameStepSize((UINT)lua_tointeger(l, 1), (float)lua_tonumber(l, 2)); + + return 0; +} + +int lua_SetFrameTexture(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + SetFrameTexture((UINT)lua_tointeger(l, 1), lua_tostring(l, 2), lua_toboolean(l, 3)); + + return 0; +} + +int lua_SetFrameEnable(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + SetFrameEnable((UINT)lua_tointeger(l, 1), lua_toboolean(l, 2)); + + return 0; +} + +int lua_ClickFrame(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + ClickFrame((UINT)lua_tointeger(l, 1)); + + return 0; +} + +int lua_SetFrameModel(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + SetFrameModel((UINT)lua_tointeger(l, 1), lua_tostring(l, 2), (UINT)lua_tointeger(l, 3), (BOOL)lua_toboolean(l, 4)); + + return 0; +} + +int lua_DestroyFrame(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + DestroyFrame((UINT)lua_tointeger(l, 1)); + + return 0; +} + +int lua_SetFrameVisible(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + SetFrameVisible((UINT)lua_tointeger(l, 1), (BOOL)lua_toboolean(l, 2)); + + return 0; +} + +int lua_SetGameUIVisible(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + SetGameUIVisible((BOOL)lua_toboolean(l, 1)); + + return 0; +} + +int lua_SetFrameCheck(lua_State* l) { + BOOL error = checkParams(l); + if (error) { + return error; + } + + SetFrameCheck((UINT)lua_tointeger(l, 1), (BOOL)lua_toboolean(l, 2)); + + return 0; +} + +//-------------------------------------------------------- + +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 new file mode 100644 index 0000000..85eef6b --- /dev/null +++ b/Src/LuaFunctions.h @@ -0,0 +1,8 @@ +#pragma once + +#include +#include + +void lua_openJassNatives(lua_State* l); + +void lua_openFrameAPI(lua_State* l); \ No newline at end of file diff --git a/Src/LuaHooks.cpp b/Src/LuaHooks.cpp new file mode 100644 index 0000000..4d60aff --- /dev/null +++ b/Src/LuaHooks.cpp @@ -0,0 +1,244 @@ +#include "LuaHooks.h" +#include +#include +#include +#include "Global.h" + +//--------------------------------------------------------------------------------- +// 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 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; + + 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"); + + 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); + + 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(); +} + +// -------------------------------------------------------------------------------- - +// Disabled functions + +void lua_disableFunctions(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"); + +} + +//--------------------------------------------------------------------------------- +// 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); +} \ No newline at end of file diff --git a/Src/LuaHooks.h b/Src/LuaHooks.h new file mode 100644 index 0000000..0a164bb --- /dev/null +++ b/Src/LuaHooks.h @@ -0,0 +1,8 @@ +#pragma once + +#include +#include + +void lua_replaceSearchers(lua_State* l); +void lua_disableFunctions(lua_State* l); +void lua_replaceFileStreamFunctions(lua_State* l); \ No newline at end of file diff --git a/Src/LuaMachine.cpp b/Src/LuaMachine.cpp index c58777f..4327501 100644 --- a/Src/LuaMachine.cpp +++ b/Src/LuaMachine.cpp @@ -1,266 +1,132 @@ #include "LuaMachine.h" - -#include +#include "LuaFunctions.h" +#include "LuaHooks.h" +#include "JassMachine.h" +#include "JassNatives.h" +#include "GameUI.h" +#include "Utils.h" +#include "Global.h" #include -#pragma comment(lib, "storm.lib") - -#include "Variables.h" -#include "LuaRegister.h" -#include "Warcraft.h" -#include "Mem.h" -lua_State* mainLuaState = NULL; +lua_State* mainState; bool running = false; +void lua_throwerr(lua_State* l); -//--------------------------------------------------------------------------------- -// 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; -} +int stacktrace(lua_State* L); -BOOL isAllowedExtension(LPCSTR fileName) { - char* fileextension = (char*)fileName + strlen(fileName); +//---------------------------------------------------------- - for (; fileextension[0] != '.'; fileextension--); - fileextension++; +lua_State* getMainState() { + if (!mainState) { + lua_State* l = mainState = luaL_newstate(); - 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; + luaL_openlibs(l); + if (!developerMode) { + lua_disableFunctions(l); + lua_replaceFileStreamFunctions(l); } + lua_openJassNatives(l); + lua_openFrameAPI(l); + // lua_open_warcraftfunctions(l); + lua_replaceSearchers(l); } - return TRUE; + return mainState; } -//--------------------------------------------------------------------------------- -// File stream only in catalog +void destroyMainState() +{ + if (mainState) { + lua_close(mainState); + mainState = NULL; + running = false; -// 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; -} + JassNatives_reset(); + GameUI_reset(); + } -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); + clearConsole(); } -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))); -} +BOOL startLua() { + destroyMainState(); -int io_open(lua_State* L) { - const char* filename = luaL_checkstring(L, 1); - const char* mode = luaL_optstring(L, 2, "r"); + lua_State* l = getMainState(); + HANDLE war3luaScript; + BOOL result = 0; - if (!isInGameCatalog(filename) || !isAllowedExtension(filename)) { - return luaL_fileresult(L, FALSE, filename); - } + if (SFileOpenFileEx(*pMapMpq, "war3map.lua", NULL, &war3luaScript)) { + SFileCloseFile(war3luaScript); - 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; -} + running = true; -// Remove -int os_remove(lua_State* L) { - const char* filename = luaL_checkstring(L, 1); + lua_pushcfunction(l, stacktrace); + lua_getglobal(l, "require"); + lua_pushstring(l, "war3map"); + if (!(result = !lua_pcall(l, 1, LUA_MULTRET, -3))) { + lua_throwerr(l); + } - if (!isInGameCatalog(filename) || !isAllowedExtension(filename)) { - return luaL_fileresult(L, FALSE, filename); + lua_pop(l, 1); } - return luaL_fileresult(L, remove(filename) == 0, filename); + return result; } -// 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); +BOOL __stdcall startLuaThread(DWORD esi) { + if (!running) { + return FALSE; } - 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"); + PJASS_STACK stack = *(PJASS_STACK*)(esi + 0x2868); - 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_State* l = (lua_State*)stack->pop()->value; + getFunctionByRef(l, stack->pop()->value); + lua_State* thread = getThreadState(l, -1); + lua_xmove(l, thread, 1); - lua_getglobal(l, "io"); + 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); - functions = { "stdin", "stdout", "stderr", "flush", "input", "lines", "output", "popen", "tmpfile", "type" }; + break; + case LUA_ERRRUN: + lua_throwerr(thread); - for (const auto& function : functions) { - lua_pushnil(l); - lua_setfield(l, -2, function); + return FALSE; } - lua_pop(l, 1); - - lua_pushnil(l); - lua_setglobal(l, "dofile"); - + return TRUE; } -//--------------------------------------------------------------------------------- -// Loader lua from mpq +//---------------------------------------------------------- +void lua_throwerr(lua_State* l) { + LPCSTR error = lua_tostring(l, -1); + running = false; -// 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)); - } + printf("--------------------Lua Error--------------------\n%s\n-------------------------------------------------\n\n", error); + MessageBox(NULL, error, "Lua Error", MB_ICONHAND | MB_TOPMOST); } -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()); +int stacktrace(lua_State* L) +{ + luaL_traceback(L, L, lua_tostring(L, -1), 0); 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_State* getThreadState(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); @@ -275,56 +141,6 @@ lua_State* createThread(lua_State* l, int index) { 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(); - } - - 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); @@ -367,71 +183,4 @@ 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/LuaMachine.h b/Src/LuaMachine.h index faf3a52..32cdfdd 100644 --- a/Src/LuaMachine.h +++ b/Src/LuaMachine.h @@ -1,24 +1,18 @@ #pragma once #include - #include -#pragma comment(lib, "lua.lib") -typedef int LUA; +extern bool running; -lua_State* getMainLuaState(); +BOOL startLua(); -void destroyMainLuaState(); +BOOL __stdcall startLuaThread(DWORD esi); -lua_State* getMainThread(lua_State* thread); +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); - -DWORD startLua(); - -BOOL CALLBACK startLuaThread(DWORD esi, DWORD edi); \ No newline at end of file +void getFunctionByRef(lua_State* l, int ref); \ No newline at end of file diff --git a/Src/Main.cpp b/Src/Main.cpp index c725604..1e996c8 100644 --- a/Src/Main.cpp +++ b/Src/Main.cpp @@ -1,42 +1,85 @@ #include #include - -#include "Variables.h" -#include "Mem.h" -#include "Hooks.h" +#include +#include "Global.h" +#include "lua.h" +#include "JassNatives.h" #include "JassMachine.h" +#include "Hooks.h" +#include "Utils.h" -BOOL APIENTRY DllMain(HMODULE hModule, UINT ul_reason_for_call, LPVOID lpReserve) -{ - if (ul_reason_for_call == 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"); - } +bool consoleMode = false; +bool developerMode = false; - printf("%s\n%s\n", LUA_COPYRIGHT, WAR3_LUA); +bool startUp(); - jassNativesInitialize(); - jassOpcodeInitialize(); +//----------------------------------------------------------------------------- - call(MakePtr(gameBase, _jassEntryPoint), jassEntryPoint); - call(MakePtr(gameBase, _getWarcraftID1), getWarcraftID); - call(MakePtr(gameBase, _getWarcraftID2), getWarcraftID); - //call(MakePtr(gameBase, 0x6025d8), glueButtonOnClick); +BOOL APIENTRY DllMain(HMODULE module, UINT reason, LPVOID reserved) { + switch (reason) { + case DLL_PROCESS_ATTACH: + if (!gameBase) { + return FALSE; } - else { + + DisableThreadLibraryCalls(module); + + if (!startUp()) { return FALSE; } + + if (consoleMode) { + system("cls"); + } + printf("%s\n%s (%s)\n", LUA_COPYRIGHT, WAR3_LUA, WAR3_LUA_VERSION_NAME); + + jassNativesParse(); + jassOpcodeInitialize(); + + attachHooks(); + + break; + case DLL_PROCESS_DETACH: + detachHooks(); + + break; } return TRUE; +} + +//----------------------------------------------------------------------------- + +bool startUp() { + DWORD handle; + DWORD size = GetFileVersionInfoSize("game.dll", &handle); + + LPSTR buffer = new char[size]; + GetFileVersionInfo("game.dll", handle, size, buffer); + + VS_FIXEDFILEINFO* verInfo; + size = sizeof(VS_FIXEDFILEINFO); + VerQueryValue(buffer, "\\", (LPVOID*)&verInfo, (UINT*)&size); + delete[] buffer; + + if (((verInfo->dwFileVersionMS >> 16) & 0xffff) != 1 || ((verInfo->dwFileVersionMS >> 0) & 0xffff) != 26 || ((verInfo->dwFileVersionLS >> 16) & 0xffff) != 0 || ((verInfo->dwFileVersionLS >> 0) & 0xffff) != 6401) + { + MessageBox(NULL, "Unsupported version of game.dll.\nLua will be unloaded.", "Error", MB_ICONHAND | MB_TOPMOST); + + return false; + } + + PSTR cmdline = GetCommandLine(); + size_t i; + for (i = strlen(cmdline); i > 0 && cmdline[i] != '\"'; i--); + + if (strstr(&cmdline[i + 1], "-dev")) { + developerMode = true; + } + + if (strstr(&cmdline[i + 1], "-console") || strstr(&cmdline[i + 1], "-debug")) { + consoleMode = openConsole(developerMode ? "Lua Console [Developer]" : "Lua Console") ? true : false; + } + + return true; } \ No newline at end of file diff --git a/Src/Utils.cpp b/Src/Utils.cpp new file mode 100644 index 0000000..7e8770a --- /dev/null +++ b/Src/Utils.cpp @@ -0,0 +1,43 @@ +#include "Utils.h" +#include "Global.h" +#include + +bool openConsole(LPCSTR title) { + FILE* console; + + bool result = AllocConsole() && !freopen_s(&console, "CONOUT$", "w", stdout); + + SetConsoleTitle(title); + + 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 new file mode 100644 index 0000000..1479226 --- /dev/null +++ b/Src/Utils.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +bool openConsole(LPCSTR title); + +void clearConsole(); \ No newline at end of file diff --git a/Src/Warcraft.cpp b/Src/Warcraft.cpp index fae4b80..4df2f36 100644 --- a/Src/Warcraft.cpp +++ b/Src/Warcraft.cpp @@ -1,178 +1,20 @@ #include "Warcraft.h" +#include "Global.h" -#include "Variables.h" -#include "fcalls.h" -#include "Mem.h" +auto getInstanceTrue = (HANDLE(__fastcall*)(UINT))((UINT_PTR)gameBase + 0x4c34d0); -PJASS_INSTANCE getJassMachine(DWORD index) { - DWORD jass_thread = *(DWORD*)(*(DWORD*)(getInstance(5) + 0x90) + index * 4); +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; } PJASS_INSTANCE getJassInstance() { - DWORD instance = getInstance(5); + HANDLE instance = getInstance(5); - return *(DWORD*)(instance + 0x14) ? *(PJASS_INSTANCE*)(*(DWORD*)(instance + 0xc) + *(DWORD*)(instance + 0x14) * 4 - 4) : NULL; + return *(UINT_PTR*)((UINT_PTR)instance + 0x14) ? *(PJASS_INSTANCE*)(*(UINT_PTR*)((UINT_PTR)instance + 0xc) + *(UINT_PTR*)((UINT_PTR)instance + 0x14) * 4 - 4) : NULL; } -DWORD getInstance(DWORD index) { - return fastcall(MakePtr(gameBase, _getInstanceProc), index); -} - - - -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); -} - -CGameUI* GetGameUI(UINT unknown0, UINT unknown1) { - return fastcall(MakePtr(gameBase, _getGameUI), unknown0, unknown1); -} - -CGameWar3* GetGameWar3(UINT unknown0) { - return fastcall(MakePtr(gameBase, _getGameWar3), unknown0); -} - -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); +HANDLE getInstance(UINT index) { + return getInstanceTrue(index); } \ No newline at end of file diff --git a/Src/Warcraft.h b/Src/Warcraft.h index fee3134..23d9463 100644 --- a/Src/Warcraft.h +++ b/Src/Warcraft.h @@ -6,15 +6,15 @@ #define _Warcraft_h typedef struct { DWORD unk; - DWORD max_size; - DWORD array; + size_t max_size; + UINT_PTR array; - UINT32 get(DWORD index) { + DWORD get(UINT index) { DWORD result = 0; if (index < max_size) { result = array + 0x10 * index; - ++* (UINT32*)(result + 0xC); + ++*(DWORD*)(result + 0xC); } return result; @@ -24,16 +24,16 @@ typedef struct { typedef struct { BYTE unk[4]; - DWORD counter; + size_t counter; DWORD* codes; // max_size = 1024 - DWORD push_code(DWORD address) { + size_t push_code(DWORD address) { codes[counter] = address; - + return counter++; } - DWORD Size() { + size_t size() { return counter; } } CODE_TABLE, * PCODE_TABLE; @@ -52,1370 +52,17 @@ typedef struct { BYTE unk1[0x10]; UINT has_sleep; BYTE unk2[0x2818]; - DWORD index; + size_t 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 -enum class 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 -}; - -PJASS_INSTANCE getJassMachine(DWORD index = 1); +PJASS_INSTANCE getJassMachine(UINT index = 1); PJASS_INSTANCE getJassInstance(); -DWORD getInstance(DWORD index); - -UINT GetOriginFrame(EOriginFrame originframe, UINT index); - -UINT GetPanelButton(UINT frame, BYTE row, BYTE column); - -CGameUI* GetGameUI(UINT unknown0 = NULL, UINT unknown1 = NULL); - -CGameWar3* GetGameWar3(UINT unknown0 = NULL); - -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); \ No newline at end of file +HANDLE getInstance(UINT index); \ No newline at end of file diff --git a/war3_lua.sln b/war3_lua.sln index 791f2ba..38017d6 100644 --- a/war3_lua.sln +++ b/war3_lua.sln @@ -7,12 +7,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "war3_lua", "war3_lua.vcxpro EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x86 = Debug|x86 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {9E1903DF-815D-4B82-A6DA-E0D40674769A}.Debug|x86.ActiveCfg = Debug|Win32 - {9E1903DF-815D-4B82-A6DA-E0D40674769A}.Debug|x86.Build.0 = Debug|Win32 {9E1903DF-815D-4B82-A6DA-E0D40674769A}.Release|x86.ActiveCfg = Release|Win32 {9E1903DF-815D-4B82-A6DA-E0D40674769A}.Release|x86.Build.0 = Release|Win32 EndGlobalSection diff --git a/war3_lua.vcxproj b/war3_lua.vcxproj index cac68d0..15f0c3f 100644 --- a/war3_lua.vcxproj +++ b/war3_lua.vcxproj @@ -100,12 +100,13 @@ true WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)3rd\StormLib\include;$(SolutionDir)3rd\lua\include + $(SolutionDir)3rd\StormLib\include;$(SolutionDir)3rd\Detours\include;$(SolutionDir)3rd\lua\include Console true - $(SolutionDir)3rd\StormLib\Build\bin\Release\Win32;$(SolutionDir)3rd\lua\lib;%(AdditionalLibraryDirectories) + $(SolutionDir)3rd\StormLib\Build\bin\Release\Win32;$(SolutionDir)3rd\Detours\lib;$(SolutionDir)3rd\lua\lib;%(AdditionalLibraryDirectories) + detours.lib;storm.lib;lua.lib;version.lib;%(AdditionalDependencies) @@ -116,14 +117,15 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)3rd\StormLib\include;$(SolutionDir)3rd\lua\include + $(SolutionDir)3rd\StormLib\include;$(SolutionDir)3rd\Detours\include;$(SolutionDir)3rd\lua\include Console true true true - $(SolutionDir)3rd\StormLib\Build\bin\Release\Win32;$(SolutionDir)3rd\lua\lib;%(AdditionalLibraryDirectories) + $(SolutionDir)3rd\StormLib\Build\bin\Release\Win32;$(SolutionDir)3rd\Detours\lib;$(SolutionDir)3rd\lua\lib;%(AdditionalLibraryDirectories) + detours.lib;storm.lib;lua.lib;version.lib;%(AdditionalDependencies) @@ -132,12 +134,13 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)3rd\StormLib\include;$(SolutionDir)3rd\lua\include + $(SolutionDir)3rd\StormLib\include;$(SolutionDir)3rd\Detours\include;$(SolutionDir)3rd\lua\include Console true - $(SolutionDir)3rd\StormLib\Build\bin\Release\Win32;$(SolutionDir)3rd\lua\lib;%(AdditionalLibraryDirectories) + $(SolutionDir)3rd\StormLib\Build\bin\Release\Win32;$(SolutionDir)3rd\Detours\lib;$(SolutionDir)3rd\lua\lib;%(AdditionalLibraryDirectories) + detours.lib;storm.lib;lua.lib;version.lib;%(AdditionalDependencies) @@ -148,45 +151,48 @@ true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true - $(SolutionDir)3rd\StormLib\include;$(SolutionDir)3rd\lua\include + $(SolutionDir)3rd\StormLib\include;$(SolutionDir)3rd\Detours\include;$(SolutionDir)3rd\lua\include Console true true true - $(SolutionDir)3rd\StormLib\Build\bin\Release\Win32;$(SolutionDir)3rd\lua\lib;%(AdditionalLibraryDirectories) + $(SolutionDir)3rd\StormLib\Build\bin\Release\Win32;$(SolutionDir)3rd\Detours\lib;$(SolutionDir)3rd\lua\lib;%(AdditionalLibraryDirectories) + detours.lib;storm.lib;lua.lib;version.lib;%(AdditionalDependencies) + + + + + + + + + + + - + - - + + + + - - - + - - - - - - - - - diff --git a/war3_lua.vcxproj.filters b/war3_lua.vcxproj.filters index f1c6fda..c66b4b6 100644 --- a/war3_lua.vcxproj.filters +++ b/war3_lua.vcxproj.filters @@ -15,71 +15,77 @@ - + + + + + + + Файлы ресурсов + + + + Исходные файлы - + Исходные файлы - + Исходные файлы - + Исходные файлы - + Исходные файлы - + Исходные файлы - + + Исходные файлы + + + Исходные файлы + + Исходные файлы - + Исходные файлы - + Файлы заголовков - + Файлы заголовков - + Файлы заголовков - + Файлы заголовков - + Файлы заголовков - + Файлы заголовков - + Файлы заголовков - + Файлы заголовков - + Файлы заголовков - + Файлы заголовков - - - - - - - - Файлы ресурсов - - \ No newline at end of file