From 2a999995d4bff7eda02ee174790e7a8f08038421 Mon Sep 17 00:00:00 2001 From: Strogoo <36897892+Strogoo@users.noreply.github.com> Date: Sun, 26 Jun 2022 03:00:49 +0300 Subject: [PATCH] Improve TeamColorMode (#8) * Improve TeamColorMode Co-authored-by: KionX <5648030+KionX@users.noreply.github.com> --- hooks/TeamColorMode.cpp | 15 +++++++ section/TeamColorMode.cpp | 84 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 hooks/TeamColorMode.cpp create mode 100644 section/TeamColorMode.cpp diff --git a/hooks/TeamColorMode.cpp b/hooks/TeamColorMode.cpp new file mode 100644 index 00000000..b4547428 --- /dev/null +++ b/hooks/TeamColorMode.cpp @@ -0,0 +1,15 @@ +#include "../define.h" +asm +( //HOOK TeamColorMode + ".section h0; .set h0,0x847E51;" + "JMP "QU(TeamColorMode)";" + "nop;" + "nop;" + "nop;" + + //HOOK TeamColorModeRenderer + ".section h1; .set h1,0x85DB68;" + "JMP "QU(TeamColorModeRenderer)";" + "nop;" + "nop;" +); \ No newline at end of file diff --git a/section/TeamColorMode.cpp b/section/TeamColorMode.cpp new file mode 100644 index 00000000..71e35eae --- /dev/null +++ b/section/TeamColorMode.cpp @@ -0,0 +1,84 @@ +int Colors[32]; + +// Basically what we do here is parsing colors from string in lua function TeamColorMode() (originally it supports only bool) +// then store them in array and then use it instead of one created from GameColors.lua +// the string should contains colors in hex format like that: "ffffffff,ffffffff,ffffffff,ffffffff,ffffffff" +// colors separated by commas, no spaces +// then stored colors will be applied to armies according to their indexes. + +void TeamColorMode() +{ + asm( + "mov dword ptr [esp+0xC], 0x1;" + "push 1;" + "push ecx;" + "call 0x90C740;" //lua_type + "add esp,0x8;" + "cmp eax, 0x1;" + "je 0x847E59;" //Return if bool + "push 1;" + "push ecx;" + "call 0x90CA90;" //lua_tostring + "add esp,0x8;" + + // Parse hex colors from string and store them to array + "mov esi, %[Colors];" + "xor ecx, ecx;" + + "Start:;" + "cmp byte ptr [eax+ecx], 0;" + "je 0x847E64;" //Return if string done + "xor edx, edx;" + + "HexStart:;" + "movsx edi, BYTE PTR [eax+ecx];" + + //Digit + "lea ebx, [edi-48];" + "cmp ebx, 9;" + "jbe Sym;" + + //Upper + "lea ebx, [edi-65];" + "cmp ebx, 5;" + "ja Lower;" + "lea ebx, [edi-55];" + "jmp Sym;" + + "Lower:;" + "lea ebx, [edi-97];" + "cmp ebx, 5;" + "ja Store;" + "lea ebx, [edi-87];" + + "Sym:;" + "sal edx, 4;" + "inc ecx;" + "add edx, ebx;" + "jmp HexStart;" + + "Store:;" + "mov DWORD PTR [esi], edx;" + "inc ecx;" + "add esi, 4;" + "jmp Start;" + : + : [Colors] "i" (Colors) + : + ); +} + +void TeamColorModeRenderer() +{ + asm( + "push eax;" + "mov ecx, dword ptr [edx];" + "mov eax, %[Colors];" + "mov ecx, dword ptr [eax+ecx*0x4];" + "pop eax;" + "jmp 0x85DB77;" + : + : [Colors] "i" (Colors) + : + ); +}