Skip to content

Commit

Permalink
Improve TeamColorMode (#8)
Browse files Browse the repository at this point in the history
* Improve TeamColorMode

Co-authored-by: KionX <5648030+KionX@users.noreply.github.com>
  • Loading branch information
Strogoo and KionX committed Jun 26, 2022
1 parent 44fd742 commit 2a99999
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
15 changes: 15 additions & 0 deletions hooks/TeamColorMode.cpp
Original file line number Diff line number Diff line change
@@ -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;"
);
84 changes: 84 additions & 0 deletions section/TeamColorMode.cpp
Original file line number Diff line number Diff line change
@@ -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)
:
);
}

0 comments on commit 2a99999

Please sign in to comment.