Skip to content

Commit

Permalink
Code deobfuscation, part 3 alexbatalov#29
Browse files Browse the repository at this point in the history
  • Loading branch information
APAmk2 authored Jan 25, 2025
2 parents 3d541f2 + cfea907 commit 1704249
Show file tree
Hide file tree
Showing 31 changed files with 1,072 additions and 1,033 deletions.
112 changes: 56 additions & 56 deletions src/actions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1060,21 +1060,21 @@ int _action_climb_ladder(Object* a1, Object* a2)
}

// 0x411F2C
int _action_use_an_item_on_object(Object* a1, Object* a2, Object* a3)
int _action_use_an_item_on_object(Object* user, Object* targetObj, Object* item)
{
Proto* proto = nullptr;
int type = FID_TYPE(a2->fid);
int type = FID_TYPE(targetObj->fid);
int sceneryType = -1;
if (type == OBJ_TYPE_SCENERY) {
if (protoGetProto(a2->pid, &proto) == -1) {
if (protoGetProto(targetObj->pid, &proto) == -1) {
return -1;
}

sceneryType = proto->scenery.type;
}

if (sceneryType != SCENERY_TYPE_LADDER_UP || a3 != nullptr) {
if (a1 == gDude) {
if (sceneryType != SCENERY_TYPE_LADDER_UP || item != nullptr) {
if (user == gDude) {
int anim = FID_ANIM_TYPE(gDude->fid);
if (anim == ANIM_WALK || anim == ANIM_RUNNING) {
reg_anim_clear(gDude);
Expand All @@ -1085,72 +1085,72 @@ int _action_use_an_item_on_object(Object* a1, Object* a2, Object* a3)
int actionPoints;
if (isInCombat()) {
animationRequestOptions = ANIMATION_REQUEST_RESERVED;
actionPoints = a1->data.critter.combat.ap;
actionPoints = user->data.critter.combat.ap;
} else {
animationRequestOptions = ANIMATION_REQUEST_UNRESERVED;
actionPoints = -1;
}

if (a1 == gDude) {
if (user == gDude) {
animationRequestOptions = ANIMATION_REQUEST_RESERVED;
}

reg_anim_begin(animationRequestOptions);

if (actionPoints != -1 || objectGetDistanceBetween(a1, a2) < 5) {
animationRegisterMoveToObject(a1, a2, actionPoints, 0);
if (actionPoints != -1 || objectGetDistanceBetween(user, targetObj) < 5) {
animationRegisterMoveToObject(user, targetObj, actionPoints, 0);
} else {
animationRegisterRunToObject(a1, a2, -1, 0);
animationRegisterRunToObject(user, targetObj, -1, 0);
}

animationRegisterCallbackForced(a1, a2, (AnimationCallback*)_is_next_to, -1);
animationRegisterCallbackForced(user, targetObj, (AnimationCallback*)_is_next_to, -1);

if (a3 == nullptr) {
animationRegisterCallback(a1, a2, (AnimationCallback*)_check_scenery_ap_cost, -1);
if (item == nullptr) {
animationRegisterCallback(user, targetObj, (AnimationCallback*)_check_scenery_ap_cost, -1);
}

int a2a = (a1->fid & 0xF000) >> 12;
if (a2a != 0) {
const char* sfx = sfxBuildCharName(a1, ANIM_PUT_AWAY, CHARACTER_SOUND_EFFECT_UNUSED);
animationRegisterPlaySoundEffect(a1, sfx, -1);
animationRegisterAnimate(a1, ANIM_PUT_AWAY, 0);
int weaponAnimCode = (user->fid & 0xF000) >> 12;
if (weaponAnimCode != 0) {
const char* sfx = sfxBuildCharName(user, ANIM_PUT_AWAY, CHARACTER_SOUND_EFFECT_UNUSED);
animationRegisterPlaySoundEffect(user, sfx, -1);
animationRegisterAnimate(user, ANIM_PUT_AWAY, 0);
}

int anim;
int objectType = FID_TYPE(a2->fid);
if (objectType == OBJ_TYPE_CRITTER && _critter_is_prone(a2)) {
int objectType = FID_TYPE(targetObj->fid);
if (objectType == OBJ_TYPE_CRITTER && _critter_is_prone(targetObj)) {
anim = ANIM_MAGIC_HANDS_GROUND;
} else if (objectType == OBJ_TYPE_SCENERY && (proto->scenery.extendedFlags & 0x01) != 0) {
anim = ANIM_MAGIC_HANDS_GROUND;
} else {
anim = ANIM_MAGIC_HANDS_MIDDLE;
}

if (sceneryType != SCENERY_TYPE_STAIRS && a3 == nullptr) {
animationRegisterAnimate(a1, anim, -1);
if (sceneryType != SCENERY_TYPE_STAIRS && item == nullptr) {
animationRegisterAnimate(user, anim, -1);
}

if (a3 != nullptr) {
if (item != nullptr) {
// TODO: Get rid of cast.
animationRegisterCallback3(a1, a2, a3, (AnimationCallback3*)_obj_use_item_on, -1);
animationRegisterCallback3(user, targetObj, item, (AnimationCallback3*)_obj_use_item_on, -1);
} else {
animationRegisterCallback(a1, a2, (AnimationCallback*)_obj_use, -1);
animationRegisterCallback(user, targetObj, (AnimationCallback*)_obj_use, -1);
}

if (a2a != 0) {
animationRegisterTakeOutWeapon(a1, a2a, -1);
if (weaponAnimCode != 0) {
animationRegisterTakeOutWeapon(user, weaponAnimCode, -1);
}

return reg_anim_end();
}

return _action_climb_ladder(a1, a2);
return _action_climb_ladder(user, targetObj);
}

// 0x412114
int _action_use_an_object(Object* a1, Object* a2)
int _action_use_an_object(Object* user, Object* targetObj)
{
return _action_use_an_item_on_object(a1, a2, nullptr);
return _action_use_an_item_on_object(user, targetObj, nullptr);
}

// 0x412134
Expand Down Expand Up @@ -1322,53 +1322,53 @@ static int _action_use_skill_in_combat_error(Object* critter)

// skill_use
// 0x41255C
int actionUseSkill(Object* a1, Object* a2, int skill)
int actionUseSkill(Object* user, Object* target, int skill)
{
switch (skill) {
case SKILL_FIRST_AID:
case SKILL_DOCTOR:
if (isInCombat()) {
// NOTE: Uninline.
return _action_use_skill_in_combat_error(a1);
return _action_use_skill_in_combat_error(user);
}

if (PID_TYPE(a2->pid) != OBJ_TYPE_CRITTER) {
if (PID_TYPE(target->pid) != OBJ_TYPE_CRITTER) {
return -1;
}
break;
case SKILL_LOCKPICK:
if (isInCombat()) {
// NOTE: Uninline.
return _action_use_skill_in_combat_error(a1);
return _action_use_skill_in_combat_error(user);
}

if (PID_TYPE(a2->pid) != OBJ_TYPE_ITEM && PID_TYPE(a2->pid) != OBJ_TYPE_SCENERY) {
if (PID_TYPE(target->pid) != OBJ_TYPE_ITEM && PID_TYPE(target->pid) != OBJ_TYPE_SCENERY) {
return -1;
}

break;
case SKILL_STEAL:
if (isInCombat()) {
// NOTE: Uninline.
return _action_use_skill_in_combat_error(a1);
return _action_use_skill_in_combat_error(user);
}

if (PID_TYPE(a2->pid) != OBJ_TYPE_ITEM && PID_TYPE(a2->pid) != OBJ_TYPE_CRITTER) {
if (PID_TYPE(target->pid) != OBJ_TYPE_ITEM && PID_TYPE(target->pid) != OBJ_TYPE_CRITTER) {
return -1;
}

if (a2 == a1) {
if (target == user) {
return -1;
}

break;
case SKILL_TRAPS:
if (isInCombat()) {
// NOTE: Uninline.
return _action_use_skill_in_combat_error(a1);
return _action_use_skill_in_combat_error(user);
}

if (PID_TYPE(a2->pid) == OBJ_TYPE_CRITTER) {
if (PID_TYPE(target->pid) == OBJ_TYPE_CRITTER) {
return -1;
}

Expand All @@ -1377,18 +1377,18 @@ int actionUseSkill(Object* a1, Object* a2, int skill)
case SKILL_REPAIR:
if (isInCombat()) {
// NOTE: Uninline.
return _action_use_skill_in_combat_error(a1);
return _action_use_skill_in_combat_error(user);
}

if (PID_TYPE(a2->pid) != OBJ_TYPE_CRITTER) {
if (PID_TYPE(target->pid) != OBJ_TYPE_CRITTER) {
break;
}

if (critterGetKillType(a2) == KILL_TYPE_ROBOT) {
if (critterGetKillType(target) == KILL_TYPE_ROBOT) {
break;
}

if (critterGetKillType(a2) == KILL_TYPE_BRAHMIN
if (critterGetKillType(target) == KILL_TYPE_BRAHMIN
&& skill == SKILL_SCIENCE) {
break;
}
Expand All @@ -1398,7 +1398,7 @@ int actionUseSkill(Object* a1, Object* a2, int skill)
int targetType = SCIENCE_REPAIR_TARGET_TYPE_DEFAULT;
configGetInt(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_SCIENCE_REPAIR_TARGET_TYPE_KEY, &targetType);
if (targetType == SCIENCE_REPAIR_TARGET_TYPE_DUDE) {
if (a2 == gDude) {
if (target == gDude) {
break;
}
} else if (targetType == SCIENCE_REPAIR_TARGET_TYPE_ANYONE) {
Expand All @@ -1418,7 +1418,7 @@ int actionUseSkill(Object* a1, Object* a2, int skill)
// skill in entire party, and this skill is his/her own best.
Object* performer = gDude;

if (a1 == gDude) {
if (user == gDude) {
Object* partyMember = partyMemberGetBestInSkill(skill);

if (partyMember == gDude) {
Expand Down Expand Up @@ -1451,7 +1451,7 @@ int actionUseSkill(Object* a1, Object* a2, int skill)

if (partyMember != nullptr) {
bool isDude = false;
if (objectGetDistanceBetween(gDude, a2) <= 1) {
if (objectGetDistanceBetween(gDude, target) <= 1) {
isDude = true;
}

Expand All @@ -1478,21 +1478,21 @@ int actionUseSkill(Object* a1, Object* a2, int skill)

if (isInCombat()) {
reg_anim_begin(ANIMATION_REQUEST_RESERVED);
animationRegisterMoveToObject(performer, a2, performer->data.critter.combat.ap, 0);
animationRegisterMoveToObject(performer, target, performer->data.critter.combat.ap, 0);
} else {
reg_anim_begin(a1 == gDude ? ANIMATION_REQUEST_RESERVED : ANIMATION_REQUEST_UNRESERVED);
if (a2 != gDude) {
if (objectGetDistanceBetween(performer, a2) >= 5) {
animationRegisterRunToObject(performer, a2, -1, 0);
reg_anim_begin(user == gDude ? ANIMATION_REQUEST_RESERVED : ANIMATION_REQUEST_UNRESERVED);
if (target != gDude) {
if (objectGetDistanceBetween(performer, target) >= 5) {
animationRegisterRunToObject(performer, target, -1, 0);
} else {
animationRegisterMoveToObject(performer, a2, -1, 0);
animationRegisterMoveToObject(performer, target, -1, 0);
}
}
}

animationRegisterCallbackForced(performer, a2, (AnimationCallback*)_is_next_to, -1);
animationRegisterCallbackForced(performer, target, (AnimationCallback*)_is_next_to, -1);

int anim = (FID_TYPE(a2->fid) == OBJ_TYPE_CRITTER && _critter_is_prone(a2)) ? ANIM_MAGIC_HANDS_GROUND : ANIM_MAGIC_HANDS_MIDDLE;
int anim = (FID_TYPE(target->fid) == OBJ_TYPE_CRITTER && _critter_is_prone(target)) ? ANIM_MAGIC_HANDS_GROUND : ANIM_MAGIC_HANDS_MIDDLE;
int fid = buildFid(OBJ_TYPE_CRITTER, performer->fid & 0xFFF, anim, 0, performer->rotation + 1);

CacheEntry* artHandle;
Expand All @@ -1504,7 +1504,7 @@ int actionUseSkill(Object* a1, Object* a2, int skill)

animationRegisterAnimate(performer, anim, -1);
// TODO: Get rid of casts.
animationRegisterCallback3(performer, a2, (void*)skill, (AnimationCallback3*)_obj_use_skill_on, -1);
animationRegisterCallback3(performer, target, (void*)skill, (AnimationCallback3*)_obj_use_skill_on, -1);
return reg_anim_end();
}

Expand Down
8 changes: 4 additions & 4 deletions src/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace fallout {
extern int rotation;

int _action_attack(Attack* attack);
int _action_use_an_item_on_object(Object* a1, Object* a2, Object* a3);
int _action_use_an_object(Object* a1, Object* a2);
int _action_use_an_item_on_object(Object* user, Object* targetObj, Object* item);
int _action_use_an_object(Object* user, Object* targetObj);
int actionPickUp(Object* critter, Object* item);
int _action_loot_container(Object* critter, Object* container);
int _action_skill_use(int a1);
int actionUseSkill(Object* a1, Object* a2, int skill);
int _action_skill_use(int skill);
int actionUseSkill(Object* user, Object* target, int skill);
bool _is_hit_from_front(Object* attacker, Object* defender);
bool _can_see(Object* a1, Object* a2);
bool _action_explode_running();
Expand Down
17 changes: 9 additions & 8 deletions src/animation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "tile.h"
#include "trait.h"
#include "vcr.h"
#include "worldmap.h"

namespace fallout {

Expand Down Expand Up @@ -1033,7 +1034,7 @@ int animationRegisterHideObjectForced(Object* object)
}

// 0x414E98
int animationRegisterCallback(void* a1, void* a2, AnimationCallback* proc, int delay)
int animationRegisterCallback(void* param1, void* param2, AnimationCallback* proc, int delay)
{
if (_check_registry(nullptr) == -1 || proc == nullptr) {
_anim_cleanup();
Expand All @@ -1045,8 +1046,8 @@ int animationRegisterCallback(void* a1, void* a2, AnimationCallback* proc, int d
animationDescription->kind = ANIM_KIND_CALLBACK;
animationDescription->extendedFlags = 0;
animationDescription->artCacheKey = nullptr;
animationDescription->param2 = a2;
animationDescription->param1 = a1;
animationDescription->param2 = param2;
animationDescription->param1 = param1;
animationDescription->callback = proc;
animationDescription->delay = delay;

Expand All @@ -1058,7 +1059,7 @@ int animationRegisterCallback(void* a1, void* a2, AnimationCallback* proc, int d
// Same as `animationRegisterCallback` but accepting 3 parameters.
//
// 0x414F20
int animationRegisterCallback3(void* a1, void* a2, void* a3, AnimationCallback3* proc, int delay)
int animationRegisterCallback3(void* param1, void* param2, void* param3, AnimationCallback3* proc, int delay)
{
if (_check_registry(nullptr) == -1 || proc == nullptr) {
_anim_cleanup();
Expand All @@ -1070,10 +1071,10 @@ int animationRegisterCallback3(void* a1, void* a2, void* a3, AnimationCallback3*
animationDescription->kind = ANIM_KIND_CALLBACK3;
animationDescription->extendedFlags = 0;
animationDescription->artCacheKey = nullptr;
animationDescription->param2 = a2;
animationDescription->param1 = a1;
animationDescription->param2 = param2;
animationDescription->param1 = param1;
animationDescription->callback3 = proc;
animationDescription->param3 = a3;
animationDescription->param3 = param3;
animationDescription->delay = delay;

gAnimationDescriptionCurrentIndex++;
Expand Down Expand Up @@ -3062,7 +3063,7 @@ void _dude_fidget()
objectGetRect(object, &rect);

Rect intersection;
if (rectIntersection(&rect, &_scr_size, &intersection) == 0 && (gMapHeader.field_34 != 97 || object->pid != 0x10000FA)) {
if (rectIntersection(&rect, &_scr_size, &intersection) == 0 && (gMapHeader.index != MAP_SPECIAL_RND_WOODSMAN || object->pid != 0x10000FA)) {
candidates[candidatesLength++] = object;
}
}
Expand Down
Loading

0 comments on commit 1704249

Please sign in to comment.