Hi!
I was working with assembly line and found this lines:
0047B2E0 MOV AX,WORD PTR DS:[EAX+64]
0047B2E4 CMP AX,6A
0047B2E8 JE SHORT StarCraf.0047B32F
0047B2EA CMP AX,6F
0047B2EE JE SHORT StarCraf.0047B32F
0047B2F0 CMP AX,71
0047B2F4 JE SHORT StarCraf.0047B32F
0047B2F6 CMP AX,72
0047B2FA JE SHORT StarCraf.0047B32F
0047B2FC CMP AX,82
0047B300 JE SHORT StarCraf.0047B32F
0047B302 CMP AX,83
0047B306 JE SHORT StarCraf.0047B32F
0047B308 CMP AX,84
0047B30C JE SHORT StarCraf.0047B32F
0047B30E CMP AX,85
0047B312 JE SHORT StarCraf.0047B32F
0047B314 CMP AX,9A
0047B318 JE SHORT StarCraf.0047B32F
0047B31A CMP AX,0A0
0047B31E JE SHORT StarCraf.0047B32F
0047B320 CMP AX,0A7
0047B324 JE SHORT StarCraf.0047B32F
0047B326 CMP AX,9B
0047B32A JE SHORT StarCraf.0047B32F
0047B32C XOR EAX,EAX
0047B32E RETN
0047B32F MOV EAX,1
0047B334 RETN
Are they equivalent to the following?
int function_0047B2E0(CUnit *unit) {
switch(unit->id) {
case UnitId::TerranCommandCenter:
case UnitId::TerranBarracks:
case UnitId::TerranFactory:
case UnitId::TerranStarport:
case UnitId::ZergInfestedCommandCenter:
case UnitId::ZergHatchery:
case UnitId::ZergLair:
case UnitId::ZergHive:
case UnitId::ProtossNexus:
case UnitId::ProtossGateway:
case UnitId::ProtossStargate:
case UnitId::ProtossRoboticsFacility:
return 1;
break;
default: return 0;
break;
}
}
And, how i should add this in GPTP?
I was thinking in:
namespace hooks {
void injectExperimental_0047B2E0() {
jmpPatch(function_0047B2E0, 0x0047B2E0, 0);
}
}
And add "injectExperimental_0047B3E0()" to "initialize.cpp", but that didn't work.
Thanks!
KYSXD
Post has been edited 1 time(s), last time on May 28 2016, 8:33 pm by KYSXD.
Since the function at 0047B3E0 takes the input unit in eax, but you can't represent that in C code, you'll have to write a wrapper for it like so:
void __declspec(naked) func0047B3E0_Wrapper() {
CUnit *unit;
int result;
__asm {
PUSHAD
MOV EBP, ESP
MOV unit, EAX
}
result = function_0047B2E0(unit);
__asm {
POPAD
MOV EAX, result
RETN
}
}
And then do jmpPatch(func0047B3E0_Wrapper, 0x0047B2E0, 0);
None.
I never use switch, but shouldn't it be "default:" (like the "case" format)?
For the wrapper, it would be:
void __declspec(naked) func0047B2E0_Wrapper() {
CUnit *unit;
Bool32 result;
__asm {
MOV unit, EAX
PUSHAD
}
result = function_0047B2E0(unit);
__asm {
POPAD
MOV EAX, result
RETN
}
}
and for the jump patch: "jmpPatch(func0047B2E0_Wrapper, 0x0047B2E0, 3);"
But you can just not add the 3 (the point of filling that is that if somebody memory edit the modded Starcraft, he won't see weird instructions born from half-cut assembly instructions, thanks to "nop" instructions filling the gap).
edit: fixed the fact that sometimes it was written 3E0 and sometimes 2E0 (2E0 being the correct way).
Also, if you just returned a value based on the result of unit->isFactory(), you could choose what's a factory or not with a dat editor.
And finally, in your switch, you wrote Necus instead of Nexus (but I guess VS would help you fix this kind of mistake)
Post has been edited 1 time(s), last time on Apr 25 2016, 11:18 am by UndeadStar.
Since the function at 0047B3E0 takes the input unit in eax, but you can't represent that in C code, you'll have to write a wrapper for it like so:
You can use __fastcall, or is that ECX?
TinyMap2 - Latest in map compression! ( 7/09/14 - New build! )
EUD Action Enabler - Lightweight EUD/EPD support! (ChaosLauncher/MPQDraft support!)
EUDDB -
topic - Help out by adding your EUDs! Or Submit reference files in the References tab!
MapSketch - New image->map generator!
EUDTrig -
topic - Quickly and easily convert offsets to EUDs! (extended players supported)
SC2 Map Texture Mask Importer/Exporter - Edit texture placement in an image editor!
This page has been viewed [img]http://farty1billion.dyndns.org/Clicky.php?img.gif[/img] times!
Thanks, Neiv, it worked fine. I'll have to remember that for future works.
UndeadStar, I corrected all those problems, thanks. The main reason i started that was to practice assembly line convertion, i found those lines and thought them could be easy to start.
Working with some functions i almost achieve a full 640x480 game layer render, but i got some troubles with some functions.
Without modifications or patch, starcraft's behaviour looks like this:
After patch:
I didn't convert all the assembler to C++ functions, just changed some values that 'make sense' to me.
The only problems i got are with these functions (Names from heinermann's
Broodwar mapping):
(Patch on these causes to 'repeat' the terrain from the top of the screen, in the place where the black section is)
0x0040C200 - BlitToBitmap
0x0040C253 - blitTileCache
0x0040C2BD - BlitTerrainCacheToGameBitmap
(Patch on this causes crash when any sprite tries to load mirror directions)
0x004D57B0 - CImage__updateGraphicData
(Patch on this causes the gradient on the bottom of the screen)
0x004808E0 - updateAllFog
I'd like to understand what those functions are doing in order to know what changes i should make, but my conversion skills aren't good (I tried a few times, but i get lost eventually)
Could anyone translate these functions to C code?
SDE, BWAPI owner, hacker.
Not entirely accurate, but draws the game tiles correctly (in a separate SDL window):
https://github.com/bwapi/bwapi/blob/SDL-Experiment/bwapi/BWAPI/GameRender.cppEDIT: That code doesn't use a cache like Starcraft does because it's not 1998 anymore.
Post has been edited 1 time(s), last time on May 29 2016, 8:34 am by Heinermann.
Wow! I'll take a look on it. Thanks!
I have a piece of code I'm currently keeping in assembly because I don't get what it does exactly.
Maybe it's an optimization of an easy manipulation, so I will share it here in case somebody get what it's doing and can explain:
__asm {
PUSHAD
MOV CL, pathingFlags
MOV AL, elevationLevel
CMP AL, 0x0C
SETB AL
XOR AL, CL
AND AL, 0x01
XOR CL, AL
MOV pathingFlags, CL
POPAD
}
unitToLoad->pathingFlags = pathingFlags;
edit: I'm especially confused with the XOR.The objective of course is to get a C code doing the same thing in a more readable way.
edit2: thank you for your help
Post has been edited 1 time(s), last time on Oct 25 2016, 7:04 am by UndeadStar.
It's ternary operator optimized to have no jump instructions, which is usually the case when you see things like SETB (which sets the specified register to 1 if the condition is true, otherwise sets it to 0)
It seems to be doing unitToLoad->pathingFlags = (elevationLevel < 0xC) ? pathingFlags | 1 : pathingFlags & ~1;
Basically setting flag 0x1 if elevationLevel < 12 an clearing it otherwise.
Post has been edited 1 time(s), last time on Oct 20 2016, 3:00 pm by FaRTy1billion.
TinyMap2 - Latest in map compression! ( 7/09/14 - New build! )
EUD Action Enabler - Lightweight EUD/EPD support! (ChaosLauncher/MPQDraft support!)
EUDDB -
topic - Help out by adding your EUDs! Or Submit reference files in the References tab!
MapSketch - New image->map generator!
EUDTrig -
topic - Quickly and easily convert offsets to EUDs! (extended players supported)
SC2 Map Texture Mask Importer/Exporter - Edit texture placement in an image editor!
This page has been viewed [img]http://farty1billion.dyndns.org/Clicky.php?img.gif[/img] times!