Added new HOOK_CARTRAVEL #90

This commit is contained in:
phobos2077
2017-04-15 21:59:18 +07:00
parent 0af8010861
commit 629641eb96
7 changed files with 97 additions and 19 deletions
+1
View File
@@ -48,6 +48,7 @@
#define HOOK_INVENWIELD (25) #define HOOK_INVENWIELD (25)
#define HOOK_ADJUSTFID (26) #define HOOK_ADJUSTFID (26)
#define HOOK_COMBATTURN (27) #define HOOK_COMBATTURN (27)
#define HOOK_CARTRAVEL (28)
//Valid arguments to list_begin //Valid arguments to list_begin
#define LIST_CRITTERS (0) #define LIST_CRITTERS (0)
+14
View File
@@ -464,3 +464,17 @@ int arg3 - unknown boolean argument
int ret1 - pass 1 at the start of turn to skip the turn, pass -1 at the end of turn to force end of combat int ret1 - pass 1 at the start of turn to skip the turn, pass -1 at the end of turn to force end of combat
-------------------------------------------
HOOK_CARTRAVEL (hs_cartravel.int)
Runs continously during worldmap travel on car.
int arg1 - vanilla car speed (between 3 and 8 "steps")
int arg2 - vanilla fuel consumption (100 and below)
int ret1 - car speed override (pass -1 if you just want to override fuel consumption)
int ret2 - fuel consumption override
+3
View File
@@ -33,6 +33,7 @@ WRAP_WATCOM_FUNC2(long, db_fwriteInt, DbFile*, file, long, value)
// perform combat turn for a given critter // perform combat turn for a given critter
WRAP_WATCOM_FUNC2(long, combat_turn, GameObject*, critter, long, isDudeTurn) WRAP_WATCOM_FUNC2(long, combat_turn, GameObject*, critter, long, isDudeTurn)
WRAP_WATCOM_FUNC1(long, critter_is_dead, GameObject*, critter) WRAP_WATCOM_FUNC1(long, critter_is_dead, GameObject*, critter)
WRAP_WATCOM_FUNC1(long, game_get_global_var, long, globalVar)
WRAP_WATCOM_FUNC1(long, gmouse_set_cursor, long, picNum) WRAP_WATCOM_FUNC1(long, gmouse_set_cursor, long, picNum)
WRAP_WATCOM_FUNC1(Window*, GNW_find, long, winRef) WRAP_WATCOM_FUNC1(Window*, GNW_find, long, winRef)
WRAP_WATCOM_FUNC0(long, intface_is_item_right_hand) WRAP_WATCOM_FUNC0(long, intface_is_item_right_hand)
@@ -87,5 +88,7 @@ WRAP_WATCOM_FUNC1(void, win_hide, DWORD, winRef)
WRAP_WATCOM_FUNC1(BYTE*, win_get_buf, DWORD, winRef) WRAP_WATCOM_FUNC1(BYTE*, win_get_buf, DWORD, winRef)
WRAP_WATCOM_FUNC1(void, win_draw, DWORD, winRef) WRAP_WATCOM_FUNC1(void, win_draw, DWORD, winRef)
WRAP_WATCOM_FUNC1(void, win_delete, DWORD, winRef) WRAP_WATCOM_FUNC1(void, win_delete, DWORD, winRef)
WRAP_WATCOM_FUNC1(void, wmCarUseGas, long, gasAmount)
WRAP_WATCOM_FUNC0(void, wmPartyWalkingStep)
WRAP_WATCOM_FUNC2(DbFile*, xfopen, const char*, fileName, const char*, flags) WRAP_WATCOM_FUNC2(DbFile*, xfopen, const char*, fileName, const char*, flags)
WRAP_WATCOM_FUNC3(long, xfseek, DbFile*, file, long, fOffset, long, origin) WRAP_WATCOM_FUNC3(long, xfseek, DbFile*, file, long, fOffset, long, origin)
+1 -1
View File
@@ -16,7 +16,7 @@ VAR_(bottom_line, DWORD)
VAR_(btable, DWORD) VAR_(btable, DWORD)
VAR_(btncnt, DWORD) VAR_(btncnt, DWORD)
VAR_(carCurrentArea, DWORD) VAR_(carCurrentArea, DWORD)
VAR_(carGasAmount, DWORD) // from 0 to 80000 VAR_(carGasAmount, long) // from 0 to 80000
VAR_(cmap, DWORD) VAR_(cmap, DWORD)
VAR_(colorTable, DWORD) VAR_(colorTable, DWORD)
VAR_(combat_free_move, DWORD) VAR_(combat_free_move, DWORD)
+1
View File
@@ -54,6 +54,7 @@ enum HookType
HOOK_INVENWIELD = 25, HOOK_INVENWIELD = 25,
HOOK_ADJUSTFID = 26, HOOK_ADJUSTFID = 26,
HOOK_COMBATTURN = 27, HOOK_COMBATTURN = 27,
HOOK_CARTRAVEL = 28,
HOOK_COUNT HOOK_COUNT
}; };
+65 -6
View File
@@ -22,10 +22,10 @@ static void __declspec(naked) UseObjOnHook() {
cmp cRet, 1; cmp cRet, 1;
jl defaulthandler; jl defaulthandler;
mov eax, rets[0]; mov eax, rets[0];
jmp end jmp end;
defaulthandler : defaulthandler:
call fo::funcoffs::protinst_use_item_on_ call fo::funcoffs::protinst_use_item_on_;
end : end:
hookend; hookend;
retn; retn;
} }
@@ -44,8 +44,8 @@ static void __declspec(naked) UseObjOnHook_item_d_take_drug() {
cmp cRet, 1; cmp cRet, 1;
jl defaulthandler; jl defaulthandler;
mov eax, rets[0]; mov eax, rets[0];
jmp end jmp end;
defaulthandler : defaulthandler:
call fo::funcoffs::item_d_take_drug_; call fo::funcoffs::item_d_take_drug_;
end: end:
hookend; hookend;
@@ -202,6 +202,61 @@ nevermind:
} }
} }
static constexpr long maxGasAmount = 80000;
static void CarTravelHookScript() {
BeginHook();
argCount = 2;
// calculate vanilla speed
int carSpeed = 3;
if (fo::func::game_get_global_var(fo::GVAR_CAR_BLOWER)) {
carSpeed += 1;
}
if (fo::func::game_get_global_var(fo::GVAR_NEW_RENO_CAR_UPGRADE)) {
carSpeed += 1;
}
if (fo::func::game_get_global_var(fo::GVAR_NEW_RENO_SUPER_CAR)) {
carSpeed += 3;
}
// calculate vanilla fuel consumption
int originalGas = fo::var::carGasAmount;
fo::var::carGasAmount = maxGasAmount;
fo::func::wmCarUseGas(100);
int consumption = maxGasAmount - fo::var::carGasAmount;
// run script
args[0] = carSpeed;
args[1] = consumption;
RunHookScript(HOOK_CARTRAVEL);
// override travel speed
if (cRet > 0 && static_cast<long>(rets[0]) >= 0) {
carSpeed = rets[0];
}
// move car on map
for (int i = 0; i < carSpeed; ++i) {
fo::func::wmPartyWalkingStep();
}
// override fuel consumption
if (cRet > 1) {
consumption = static_cast<long>(rets[1]);
}
// consume fuel
fo::var::carGasAmount = max(originalGas - consumption, 0);
EndHook();
}
static const DWORD CarTravelHack_back = 0x4BFF43;
static void __declspec(naked) CarTravelHack() {
__asm {
pushad;
call CarTravelHookScript;
popad;
jmp CarTravelHack_back;
}
}
void InitMiscHookScripts() { void InitMiscHookScripts() {
LoadHookScript("hs_useobjon", HOOK_USEOBJON); LoadHookScript("hs_useobjon", HOOK_USEOBJON);
HookCalls(UseObjOnHook, { 0x49C606, 0x473619 }); HookCalls(UseObjOnHook, { 0x49C606, 0x473619 });
@@ -240,6 +295,10 @@ void InitMiscHookScripts() {
0x458403 0x458403
}); });
MakeJump(0x456BA2, PerceptionRangeBonusHack); MakeJump(0x456BA2, PerceptionRangeBonusHack);
LoadHookScript("hs_cartravel", HOOK_CARTRAVEL);
MakeJump(0x4BFEF1, CarTravelHack);
BlockCall(0x4BFF6E); // vanilla wnCarUseGas(100) call
} }
} }
+12 -12
View File
@@ -222,7 +222,7 @@ static __declspec(naked) void PathfinderFix() {
} }
} }
void ApplyWorldLimitsPatches() { void WorldLimitsPatches() {
DWORD date = GetConfigInt("Misc", "LocalMapXLimit", 0); DWORD date = GetConfigInt("Misc", "LocalMapXLimit", 0);
if (date) { if (date) {
dlog("Applying local map x limit patch.", DL_INIT); dlog("Applying local map x limit patch.", DL_INIT);
@@ -268,7 +268,7 @@ void ApplyWorldLimitsPatches() {
} }
} }
void ApplyTimeLimitPatch() { void TimeLimitPatch() {
int limit = GetConfigInt("Misc", "TimeLimit", 13); int limit = GetConfigInt("Misc", "TimeLimit", 13);
if (limit == -2) { if (limit == -2) {
limit = 14; limit = 14;
@@ -313,7 +313,7 @@ void ApplyTimeLimitPatch() {
} }
} }
void ApplyTownMapsHotkeyFix() { void TownMapsHotkeyFix() {
if (GetConfigInt("Misc", "TownMapHotkeysFix", 1)) { if (GetConfigInt("Misc", "TownMapHotkeysFix", 1)) {
dlog("Applying town map hotkeys patch.", DL_INIT); dlog("Applying town map hotkeys patch.", DL_INIT);
MakeCall(0x4C4945, wmTownMapFunc_hack); MakeCall(0x4C4945, wmTownMapFunc_hack);
@@ -321,7 +321,7 @@ void ApplyTownMapsHotkeyFix() {
} }
} }
void ApplyWorldmapFpsPatch() { void WorldmapFpsPatch() {
if (GetConfigInt("Misc", "WorldMapFPSPatch", 0)) { if (GetConfigInt("Misc", "WorldMapFPSPatch", 0)) {
dlog("Applying world map fps patch.", DL_INIT); dlog("Applying world map fps patch.", DL_INIT);
if (*(DWORD*)0x4BFE5E != 0x8d16) { if (*(DWORD*)0x4BFE5E != 0x8d16) {
@@ -349,7 +349,7 @@ void ApplyWorldmapFpsPatch() {
} }
} }
void ApplyPathfinderFix() { void PathfinderFixInit() {
//if(GetConfigInt("Misc", "PathfinderFix", 0)) { //if(GetConfigInt("Misc", "PathfinderFix", 0)) {
dlog("Applying pathfinder patch.", DL_INIT); dlog("Applying pathfinder patch.", DL_INIT);
SafeWrite32(0x004C1FF2, ((DWORD)&PathfinderFix3) - 0x004c1ff6); SafeWrite32(0x004C1FF2, ((DWORD)&PathfinderFix3) - 0x004c1ff6);
@@ -359,7 +359,7 @@ void ApplyPathfinderFix() {
//} //}
} }
void ApplyStartingStatePatches() { void StartingStatePatches() {
int date = GetConfigInt("Misc", "StartYear", -1); int date = GetConfigInt("Misc", "StartYear", -1);
if (date > 0) { if (date > 0) {
dlog("Applying starting year patch.", DL_INIT); dlog("Applying starting year patch.", DL_INIT);
@@ -411,12 +411,12 @@ void ApplyStartingStatePatches() {
} }
void Worldmap::init() { void Worldmap::init() {
ApplyPathfinderFix(); PathfinderFixInit();
ApplyStartingStatePatches(); StartingStatePatches();
ApplyTimeLimitPatch(); TimeLimitPatch();
ApplyTownMapsHotkeyFix(); TownMapsHotkeyFix();
ApplyWorldLimitsPatches(); WorldLimitsPatches();
ApplyWorldmapFpsPatch(); WorldmapFpsPatch();
LoadGameHook::OnGameReset() += []() { LoadGameHook::OnGameReset() += []() {
SetCarInterfaceArt(0x1B1); SetCarInterfaceArt(0x1B1);