Skip to content

Commit

Permalink
change GiveNukeSiloAmmo() (#15)
Browse files Browse the repository at this point in the history
* change GiveNukeSiloAmmo()

* Small fixes

---------

Co-authored-by: KionX <>
  • Loading branch information
Strogoo authored Apr 13, 2023
1 parent f5bcbe7 commit 198e00f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
10 changes: 10 additions & 0 deletions hooks/GiveNukeSiloAmmo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "../define.h"
asm(
//HOOK Check args
".section h0; .set h0,0x6CED74;"
"JMP "QU(SiloAmmoCheckArgs)";"

//HOOK Set blocks
".section h1; .set h1,0x6CEDF1;"
"JMP "QU(SiloAmmoSetBlocks)";"
);
51 changes: 51 additions & 0 deletions section/GiveNukeSiloAmmo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Change unit:GiveNukeSiloAmmo(int) behaviour to be able to set work progress manually
// this way we can save half done missiles after unit transfer (works with SMLs and SMDs)
//
// Now when passing any second argumnent (just use True), the function will change the number of finished blocks instead of adding the missile to silo
// As you know missile launchers build missiles in different way compare to normal factories (see Moho::CAiSiloBuildImpl::SiloTick)
// every job is divided into "blocks". The number of blocks is calculated using this formula:
//
// blocks = missileBuildTime / launcherBuildPower * 10
//
// for standard SML there will be 450000/1500*10 = 3000 blocks
//
// so 3000 blocks is 100%. Then if you need to set, let say, 35% just send 1050 (integer) as first argument and True\False\whatever as second. Example:
// unit:GiveNukeSiloAmmo(1050, true)

char Blocks[1];

void SiloAmmoCheckArgs()
{
asm(
"mov %[Blocks], 0;"
"cmp eax, 2;"
"je 0x6CED8B;"
"cmp eax, 3;" //change blocks if third arg exists
"jne 0x6CED79;"
"mov %[Blocks], 1;"
"jmp 0x6CED8B;"
:
: [Blocks] "m" (Blocks)
:
);
}

void SiloAmmoSetBlocks()
{
asm(
"cmp %[Blocks], 0;"
"je Finish;"
"mov [ebx+0x48], eax;" //here we set the number of blocks. This value is used by Moho::CAiSiloBuildImpl::SiloTick for calculations
"jmp 0x6CEDFA;"

//default code
"Finish:;"
"mov edx, [edi];"
"push eax;"
"push 1;"
"jmp 0x6CEDF6;"
:
: [Blocks] "m" (Blocks)
:
);
}

0 comments on commit 198e00f

Please sign in to comment.