fallout2-ce/src/proto.cc

1907 lines
61 KiB
C++
Raw Normal View History

2022-05-19 01:51:26 -07:00
#include "proto.h"
2022-09-15 02:38:23 -07:00
#include <stdio.h>
#include <string.h>
2022-05-19 01:51:26 -07:00
#include "art.h"
#include "character_editor.h"
#include "combat.h"
#include "config.h"
#include "critter.h"
#include "debug.h"
#include "dialog.h"
#include "game.h"
#include "game_movie.h"
#include "interface.h"
#include "map.h"
#include "memory.h"
#include "object.h"
#include "perk.h"
#include "settings.h"
2022-05-19 01:51:26 -07:00
#include "skill.h"
#include "stat.h"
#include "trait.h"
2022-09-23 05:43:44 -07:00
namespace fallout {
2022-06-19 04:42:07 -07:00
static int _proto_critter_init(Proto* a1, int a2);
static int objectCritterCombatDataRead(CritterCombatData* data, File* stream);
static int objectCritterCombatDataWrite(CritterCombatData* data, File* stream);
static int _proto_update_gen(Object* obj);
static int _proto_header_load();
static int protoItemDataRead(ItemProtoData* item_data, int type, File* stream);
static int protoSceneryDataRead(SceneryProtoData* scenery_data, int type, File* stream);
static int protoRead(Proto* buf, File* stream);
static int protoItemDataWrite(ItemProtoData* item_data, int type, File* stream);
static int protoSceneryDataWrite(SceneryProtoData* scenery_data, int type, File* stream);
static int protoWrite(Proto* buf, File* stream);
static int _proto_load_pid(int pid, Proto** out_proto);
static int _proto_find_free_subnode(int type, Proto** out_ptr);
static void _proto_remove_some_list(int type);
static void _proto_remove_list(int type);
static int _proto_new_id(int a1);
static int _proto_max_id(int a1);
2022-05-19 01:51:26 -07:00
// 0x50CF3C
2022-06-19 04:42:07 -07:00
static char _aProto_0[] = "proto\\";
2022-05-19 01:51:26 -07:00
// 0x50D1B0
2022-06-19 04:42:07 -07:00
static char _aDrugStatSpecia[] = "Drug Stat (Special)";
2022-05-19 01:51:26 -07:00
// 0x50D1C4
2022-06-19 04:42:07 -07:00
static char _aNone_1[] = "None";
2022-05-19 01:51:26 -07:00
// 0x51C18C
2022-05-28 02:34:49 -07:00
char _cd_path_base[COMPAT_MAX_PATH];
2022-05-19 01:51:26 -07:00
// 0x51C290
2022-06-19 04:42:07 -07:00
static ProtoList _protoLists[11] = {
2022-05-19 01:51:26 -07:00
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
};
// 0x51C340
2022-06-19 04:42:07 -07:00
static const size_t _proto_sizes[11] = {
2022-05-19 01:51:26 -07:00
sizeof(ItemProto), // 0x84
sizeof(CritterProto), // 0x1A0
sizeof(SceneryProto), // 0x38
sizeof(WallProto), // 0x24
sizeof(TileProto), // 0x1C
sizeof(MiscProto), // 0x1C
0,
0,
0,
0,
0,
};
// 0x51C36C
2022-06-19 04:42:07 -07:00
static int _protos_been_initialized = 0;
2022-05-19 01:51:26 -07:00
// obj_dude_proto
// 0x51C370
2022-06-19 04:42:07 -07:00
static CritterProto gDudeProto = {
2022-05-19 01:51:26 -07:00
0x1000000,
-1,
0x1000001,
0,
0,
0x20000000,
0,
-1,
0,
{ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 18, 0, 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 23, 0 },
{ 0 },
{ 0 },
0,
0,
0,
0,
-1,
0,
0,
};
// 0x51C534
2022-06-19 04:42:07 -07:00
static char* _proto_path_base = _aProto_0;
2022-05-19 01:51:26 -07:00
// 0x51C538
2022-06-19 04:42:07 -07:00
static int _init_true = 0;
2022-05-19 01:51:26 -07:00
// 0x51C53C
2022-06-19 04:42:07 -07:00
static int _retval = 0;
2022-05-19 01:51:26 -07:00
// 0x66452C
2022-06-19 04:42:07 -07:00
static char* _mp_perk_code_None;
2022-05-19 01:51:26 -07:00
// 0x664530
2022-06-19 04:42:07 -07:00
static char* _mp_perk_code_strs[PERK_COUNT];
2022-05-19 01:51:26 -07:00
// 0x66470C
2022-06-19 04:42:07 -07:00
static char* _mp_critter_stats_list;
2022-05-19 01:51:26 -07:00
// 0x664710
2022-06-19 04:42:07 -07:00
static char* _critter_stats_list_None;
2022-05-19 01:51:26 -07:00
// 0x664714
2022-06-19 04:42:07 -07:00
static char* _critter_stats_list_strs[STAT_COUNT];
2022-05-19 01:51:26 -07:00
// Message list by object type
// 0 - pro_item.msg
// 1 - pro_crit.msg
// 2 - pro_scen.msg
// 3 - pro_wall.msg
// 4 - pro_tile.msg
// 5 - pro_misc.msg
//
// 0x6647AC
2022-06-19 04:42:07 -07:00
static MessageList _proto_msg_files[6];
2022-05-19 01:51:26 -07:00
// 0x6647DC
2022-06-19 04:42:07 -07:00
static char* gRaceTypeNames[RACE_TYPE_COUNT];
2022-05-19 01:51:26 -07:00
// 0x6647E4
2022-06-19 04:42:07 -07:00
static char* gSceneryTypeNames[SCENERY_TYPE_COUNT];
2022-05-19 01:51:26 -07:00
// proto.msg
//
// 0x6647FC
MessageList gProtoMessageList;
// 0x664804
2022-06-19 04:42:07 -07:00
static char* gMaterialTypeNames[MATERIAL_TYPE_COUNT];
2022-05-19 01:51:26 -07:00
// "<None>" from proto.msg
//
// 0x664824
char* _proto_none_str;
// 0x664828
2022-06-19 04:42:07 -07:00
static char* gBodyTypeNames[BODY_TYPE_COUNT];
2022-05-19 01:51:26 -07:00
// 0x664834
2022-06-19 04:42:07 -07:00
static char* gItemTypeNames[ITEM_TYPE_COUNT];
2022-05-19 01:51:26 -07:00
// 0x66484C
2022-06-19 04:42:07 -07:00
static char* gDamageTypeNames[DAMAGE_TYPE_COUNT];
2022-05-19 01:51:26 -07:00
// 0x66486C
2022-06-19 04:42:07 -07:00
static char* gCaliberTypeNames[CALIBER_TYPE_COUNT];
2022-05-19 01:51:26 -07:00
// Perk names.
//
// 0x6648B8
2022-06-19 04:42:07 -07:00
static char** _perk_code_strs;
2022-05-19 01:51:26 -07:00
// Stat names.
//
// 0x6648BC
2022-06-19 04:42:07 -07:00
static char** _critter_stats_list;
2022-05-19 01:51:26 -07:00
// NOTE: Inlined.
void _proto_make_path(char* path, int pid)
{
strcpy(path, _cd_path_base);
strcat(path, _proto_path_base);
if (pid != -1) {
strcat(path, artGetObjectTypeName(PID_TYPE(pid)));
}
}
2022-05-19 01:51:26 -07:00
// Append proto file name to proto_path from proto.lst.
//
// 0x49E758
int _proto_list_str(int pid, char* proto_path)
{
if (pid == -1) {
return -1;
}
2022-07-06 05:02:02 -07:00
if (proto_path == NULL) {
2022-05-19 01:51:26 -07:00
return -1;
}
char path[COMPAT_MAX_PATH];
_proto_make_path(path, pid);
2022-05-19 01:51:26 -07:00
strcat(path, "\\");
strcat(path, artGetObjectTypeName(PID_TYPE(pid)));
2022-05-19 01:51:26 -07:00
strcat(path, ".lst");
File* stream = fileOpen(path, "rt");
2022-05-19 01:51:26 -07:00
int i = 1;
char string[256];
while (fileReadString(string, sizeof(string), stream)) {
2022-05-19 01:51:26 -07:00
if (i == (pid & 0xFFFFFF)) {
break;
}
i++;
}
fileClose(stream);
if (i != (pid & 0xFFFFFF)) {
return -1;
}
char* pch = strchr(string, ' ');
if (pch != NULL) {
*pch = '\0';
}
2022-10-26 00:17:39 -07:00
pch = strpbrk(string, "\r\n");
if (pch != NULL) {
*pch = '\0';
2022-05-19 01:51:26 -07:00
}
strcpy(proto_path, string);
2022-05-19 01:51:26 -07:00
return 0;
}
2023-04-18 23:21:38 -07:00
// 0x49E984
size_t proto_size(int type)
{
return type >= 0 && type < OBJ_TYPE_COUNT ? _proto_sizes[type] : 0;
}
2022-05-19 01:51:26 -07:00
// 0x49E99C
bool _proto_action_can_use(int pid)
{
Proto* proto;
if (protoGetProto(pid, &proto) == -1) {
return false;
}
if ((proto->item.extendedFlags & 0x0800) != 0) {
return true;
}
if (PID_TYPE(pid) == OBJ_TYPE_ITEM && proto->item.type == ITEM_TYPE_CONTAINER) {
2022-05-19 01:51:26 -07:00
return true;
}
return false;
}
// 0x49E9DC
bool _proto_action_can_use_on(int pid)
{
Proto* proto;
if (protoGetProto(pid, &proto) == -1) {
return false;
}
if ((proto->item.extendedFlags & 0x1000) != 0) {
return true;
}
if (PID_TYPE(pid) == OBJ_TYPE_ITEM && proto->item.type == ITEM_TYPE_DRUG) {
2022-05-19 01:51:26 -07:00
return true;
}
return false;
}
// 0x49EA24
bool _proto_action_can_talk_to(int pid)
{
Proto* proto;
if (protoGetProto(pid, &proto) == -1) {
return false;
}
if (PID_TYPE(pid) == OBJ_TYPE_CRITTER) {
2022-05-19 01:51:26 -07:00
return true;
}
if (proto->critter.extendedFlags & 0x4000) {
return true;
}
return false;
}
// Likely returns true if item with given pid can be picked up.
//
// 0x49EA5C
int _proto_action_can_pickup(int pid)
{
if (PID_TYPE(pid) != OBJ_TYPE_ITEM) {
2022-05-19 01:51:26 -07:00
return false;
}
Proto* proto;
if (protoGetProto(pid, &proto) == -1) {
return false;
}
if (proto->item.type == ITEM_TYPE_CONTAINER) {
return (proto->item.extendedFlags & 0x8000) != 0;
}
return true;
}
// 0x49EAA4
char* protoGetMessage(int pid, int message)
{
char* v1 = _proto_none_str;
Proto* proto;
if (protoGetProto(pid, &proto) != -1) {
if (proto->messageId != -1) {
MessageList* messageList = &(_proto_msg_files[PID_TYPE(pid)]);
2022-05-19 01:51:26 -07:00
MessageListItem messageListItem;
messageListItem.num = proto->messageId + message;
if (messageListGetItem(messageList, &messageListItem)) {
v1 = messageListItem.text;
}
}
}
return v1;
}
// 0x49EAFC
char* protoGetName(int pid)
{
if (pid == 0x1000000) {
return critterGetName(gDude);
}
return protoGetMessage(pid, PROTOTYPE_MESSAGE_NAME);
}
// 0x49EB1C
char* protoGetDescription(int pid)
{
return protoGetMessage(pid, PROTOTYPE_MESSAGE_DESCRIPTION);
}
// 0x49EDB4
2022-06-19 04:42:07 -07:00
static int _proto_critter_init(Proto* a1, int a2)
2022-05-19 01:51:26 -07:00
{
if (!_protos_been_initialized) {
return -1;
}
int v1 = a2 & 0xFFFFFF;
a1->pid = -1;
a1->messageId = 100 * v1;
a1->fid = buildFid(OBJ_TYPE_CRITTER, v1 - 1, 0, 0, 0);
2022-05-19 01:51:26 -07:00
a1->critter.lightDistance = 0;
a1->critter.lightIntensity = 0;
a1->critter.flags = 0x20000000;
a1->critter.extendedFlags = 0x6000;
a1->critter.sid = -1;
a1->critter.data.flags = 0;
a1->critter.data.bodyType = 0;
a1->critter.headFid = -1;
a1->critter.aiPacket = 1;
if (!artExists(a1->fid)) {
a1->fid = buildFid(OBJ_TYPE_CRITTER, 0, 0, 0, 0);
2022-05-19 01:51:26 -07:00
}
CritterProtoData* data = &(a1->critter.data);
data->experience = 60;
data->killType = 0;
data->damageType = 0;
protoCritterDataResetStats(data);
protoCritterDataResetSkills(data);
return 0;
}
// 0x49EEA4
void objectDataReset(Object* obj)
{
// NOTE: Original code is slightly different. It uses loop to zero object
// data byte by byte.
memset(&(obj->data), 0, sizeof(obj->data));
}
// 0x49EEB8
2022-06-19 04:42:07 -07:00
static int objectCritterCombatDataRead(CritterCombatData* data, File* stream)
2022-05-19 01:51:26 -07:00
{
if (fileReadInt32(stream, &(data->damageLastTurn)) == -1) return -1;
if (fileReadInt32(stream, &(data->maneuver)) == -1) return -1;
if (fileReadInt32(stream, &(data->ap)) == -1) return -1;
if (fileReadInt32(stream, &(data->results)) == -1) return -1;
if (fileReadInt32(stream, &(data->aiPacket)) == -1) return -1;
if (fileReadInt32(stream, &(data->team)) == -1) return -1;
if (fileReadInt32(stream, &(data->whoHitMeCid)) == -1) return -1;
return 0;
}
// 0x49EF40
2022-06-19 04:42:07 -07:00
static int objectCritterCombatDataWrite(CritterCombatData* data, File* stream)
2022-05-19 01:51:26 -07:00
{
if (fileWriteInt32(stream, data->damageLastTurn) == -1) return -1;
if (fileWriteInt32(stream, data->maneuver) == -1) return -1;
if (fileWriteInt32(stream, data->ap) == -1) return -1;
if (fileWriteInt32(stream, data->results) == -1) return -1;
if (fileWriteInt32(stream, data->aiPacket) == -1) return -1;
if (fileWriteInt32(stream, data->team) == -1) return -1;
if (fileWriteInt32(stream, data->whoHitMeCid) == -1) return -1;
return 0;
}
// 0x49F004
int objectDataRead(Object* obj, File* stream)
{
Proto* proto;
2022-08-31 08:52:01 -07:00
int temp;
2022-05-19 01:51:26 -07:00
Inventory* inventory = &(obj->data.inventory);
if (fileReadInt32(stream, &(inventory->length)) == -1) return -1;
if (fileReadInt32(stream, &(inventory->capacity)) == -1) return -1;
2022-08-31 08:52:01 -07:00
// CE: Original code reads inventory items pointer which is meaningless.
if (fileReadInt32(stream, &temp) == -1) return -1;
2022-05-19 01:51:26 -07:00
if (PID_TYPE(obj->pid) == OBJ_TYPE_CRITTER) {
2022-05-19 01:51:26 -07:00
if (fileReadInt32(stream, &(obj->data.critter.field_0)) == -1) return -1;
if (objectCritterCombatDataRead(&(obj->data.critter.combat), stream) == -1) return -1;
if (fileReadInt32(stream, &(obj->data.critter.hp)) == -1) return -1;
if (fileReadInt32(stream, &(obj->data.critter.radiation)) == -1) return -1;
if (fileReadInt32(stream, &(obj->data.critter.poison)) == -1) return -1;
} else {
if (fileReadInt32(stream, &(obj->data.flags)) == -1) return -1;
if (obj->data.flags == 0xCCCCCCCC) {
debugPrint("\nNote: Reading pud: updated_flags was un-Set!");
obj->data.flags = 0;
}
switch (PID_TYPE(obj->pid)) {
2022-05-19 01:51:26 -07:00
case OBJ_TYPE_ITEM:
if (protoGetProto(obj->pid, &proto) == -1) return -1;
switch (proto->item.type) {
case ITEM_TYPE_WEAPON:
if (fileReadInt32(stream, &(obj->data.item.weapon.ammoQuantity)) == -1) return -1;
if (fileReadInt32(stream, &(obj->data.item.weapon.ammoTypePid)) == -1) return -1;
break;
case ITEM_TYPE_AMMO:
if (fileReadInt32(stream, &(obj->data.item.ammo.quantity)) == -1) return -1;
break;
case ITEM_TYPE_MISC:
if (fileReadInt32(stream, &(obj->data.item.misc.charges)) == -1) return -1;
break;
case ITEM_TYPE_KEY:
if (fileReadInt32(stream, &(obj->data.item.key.keyCode)) == -1) return -1;
break;
default:
break;
}
break;
case OBJ_TYPE_SCENERY:
if (protoGetProto(obj->pid, &proto) == -1) return -1;
switch (proto->scenery.type) {
case SCENERY_TYPE_DOOR:
if (fileReadInt32(stream, &(obj->data.scenery.door.openFlags)) == -1) return -1;
break;
case SCENERY_TYPE_STAIRS:
if (fileReadInt32(stream, &(obj->data.scenery.stairs.destinationBuiltTile)) == -1) return -1;
if (fileReadInt32(stream, &(obj->data.scenery.stairs.destinationMap)) == -1) return -1;
2022-05-19 01:51:26 -07:00
break;
case SCENERY_TYPE_ELEVATOR:
if (fileReadInt32(stream, &(obj->data.scenery.elevator.type)) == -1) return -1;
if (fileReadInt32(stream, &(obj->data.scenery.elevator.level)) == -1) return -1;
2022-05-19 01:51:26 -07:00
break;
case SCENERY_TYPE_LADDER_UP:
if (gMapHeader.version == 19) {
if (fileReadInt32(stream, &(obj->data.scenery.ladder.destinationBuiltTile)) == -1) return -1;
2022-05-19 01:51:26 -07:00
} else {
if (fileReadInt32(stream, &(obj->data.scenery.ladder.destinationMap)) == -1) return -1;
if (fileReadInt32(stream, &(obj->data.scenery.ladder.destinationBuiltTile)) == -1) return -1;
2022-05-19 01:51:26 -07:00
}
break;
case SCENERY_TYPE_LADDER_DOWN:
if (gMapHeader.version == 19) {
if (fileReadInt32(stream, &(obj->data.scenery.ladder.destinationBuiltTile)) == -1) return -1;
2022-05-19 01:51:26 -07:00
} else {
if (fileReadInt32(stream, &(obj->data.scenery.ladder.destinationMap)) == -1) return -1;
if (fileReadInt32(stream, &(obj->data.scenery.ladder.destinationBuiltTile)) == -1) return -1;
2022-05-19 01:51:26 -07:00
}
break;
}
break;
case OBJ_TYPE_MISC:
2022-12-13 03:34:49 -08:00
if (isExitGridPid(obj->pid)) {
2022-05-19 01:51:26 -07:00
if (fileReadInt32(stream, &(obj->data.misc.map)) == -1) return -1;
if (fileReadInt32(stream, &(obj->data.misc.tile)) == -1) return -1;
if (fileReadInt32(stream, &(obj->data.misc.elevation)) == -1) return -1;
if (fileReadInt32(stream, &(obj->data.misc.rotation)) == -1) return -1;
}
break;
}
}
return 0;
}
// 0x49F428
int objectDataWrite(Object* obj, File* stream)
{
Proto* proto;
ObjectData* data = &(obj->data);
if (fileWriteInt32(stream, data->inventory.length) == -1) return -1;
if (fileWriteInt32(stream, data->inventory.capacity) == -1) return -1;
2022-08-31 08:52:01 -07:00
// CE: Original code writes inventory items pointer, which is meaningless.
if (fileWriteInt32(stream, 0) == -1) return -1;
2022-05-19 01:51:26 -07:00
if (PID_TYPE(obj->pid) == OBJ_TYPE_CRITTER) {
2022-05-19 01:51:26 -07:00
if (fileWriteInt32(stream, data->flags) == -1) return -1;
if (objectCritterCombatDataWrite(&(obj->data.critter.combat), stream) == -1) return -1;
if (fileWriteInt32(stream, data->critter.hp) == -1) return -1;
if (fileWriteInt32(stream, data->critter.radiation) == -1) return -1;
if (fileWriteInt32(stream, data->critter.poison) == -1) return -1;
} else {
if (fileWriteInt32(stream, data->flags) == -1) return -1;
switch (PID_TYPE(obj->pid)) {
2022-05-19 01:51:26 -07:00
case OBJ_TYPE_ITEM:
if (protoGetProto(obj->pid, &proto) == -1) return -1;
switch (proto->item.type) {
case ITEM_TYPE_WEAPON:
if (fileWriteInt32(stream, data->item.weapon.ammoQuantity) == -1) return -1;
if (fileWriteInt32(stream, data->item.weapon.ammoTypePid) == -1) return -1;
break;
case ITEM_TYPE_AMMO:
if (fileWriteInt32(stream, data->item.ammo.quantity) == -1) return -1;
break;
case ITEM_TYPE_MISC:
if (fileWriteInt32(stream, data->item.misc.charges) == -1) return -1;
break;
case ITEM_TYPE_KEY:
if (fileWriteInt32(stream, data->item.key.keyCode) == -1) return -1;
break;
}
break;
case OBJ_TYPE_SCENERY:
if (protoGetProto(obj->pid, &proto) == -1) return -1;
switch (proto->scenery.type) {
case SCENERY_TYPE_DOOR:
if (fileWriteInt32(stream, data->scenery.door.openFlags) == -1) return -1;
break;
case SCENERY_TYPE_STAIRS:
if (fileWriteInt32(stream, data->scenery.stairs.destinationBuiltTile) == -1) return -1;
if (fileWriteInt32(stream, data->scenery.stairs.destinationMap) == -1) return -1;
2022-05-19 01:51:26 -07:00
break;
case SCENERY_TYPE_ELEVATOR:
if (fileWriteInt32(stream, data->scenery.elevator.type) == -1) return -1;
if (fileWriteInt32(stream, data->scenery.elevator.level) == -1) return -1;
2022-05-19 01:51:26 -07:00
break;
case SCENERY_TYPE_LADDER_UP:
if (fileWriteInt32(stream, data->scenery.ladder.destinationMap) == -1) return -1;
if (fileWriteInt32(stream, data->scenery.ladder.destinationBuiltTile) == -1) return -1;
2022-05-19 01:51:26 -07:00
break;
case SCENERY_TYPE_LADDER_DOWN:
if (fileWriteInt32(stream, data->scenery.ladder.destinationMap) == -1) return -1;
if (fileWriteInt32(stream, data->scenery.ladder.destinationBuiltTile) == -1) return -1;
2022-05-19 01:51:26 -07:00
break;
default:
break;
}
break;
case OBJ_TYPE_MISC:
2022-12-13 03:34:49 -08:00
if (isExitGridPid(obj->pid)) {
2022-05-19 01:51:26 -07:00
if (fileWriteInt32(stream, data->misc.map) == -1) return -1;
if (fileWriteInt32(stream, data->misc.tile) == -1) return -1;
if (fileWriteInt32(stream, data->misc.elevation) == -1) return -1;
if (fileWriteInt32(stream, data->misc.rotation) == -1) return -1;
}
break;
default:
break;
}
}
return 0;
}
// 0x49F73C
2022-06-19 04:42:07 -07:00
static int _proto_update_gen(Object* obj)
2022-05-19 01:51:26 -07:00
{
Proto* proto;
if (!_protos_been_initialized) {
return -1;
}
ObjectData* data = &(obj->data);
data->inventory.length = 0;
data->inventory.capacity = 0;
data->inventory.items = NULL;
if (protoGetProto(obj->pid, &proto) == -1) {
return -1;
}
switch (PID_TYPE(obj->pid)) {
2022-05-19 01:51:26 -07:00
case OBJ_TYPE_ITEM:
switch (proto->item.type) {
case ITEM_TYPE_CONTAINER:
data->flags = 0;
break;
case ITEM_TYPE_WEAPON:
data->item.weapon.ammoQuantity = proto->item.data.weapon.ammoCapacity;
data->item.weapon.ammoTypePid = proto->item.data.weapon.ammoTypePid;
break;
case ITEM_TYPE_AMMO:
data->item.ammo.quantity = proto->item.data.ammo.quantity;
break;
case ITEM_TYPE_MISC:
data->item.misc.charges = proto->item.data.misc.charges;
break;
case ITEM_TYPE_KEY:
data->item.key.keyCode = proto->item.data.key.keyCode;
break;
}
break;
case OBJ_TYPE_SCENERY:
switch (proto->scenery.type) {
case SCENERY_TYPE_DOOR:
data->scenery.door.openFlags = proto->scenery.data.door.openFlags;
break;
case SCENERY_TYPE_STAIRS:
data->scenery.stairs.destinationBuiltTile = proto->scenery.data.stairs.field_0;
data->scenery.stairs.destinationMap = proto->scenery.data.stairs.field_4;
2022-05-19 01:51:26 -07:00
break;
case SCENERY_TYPE_ELEVATOR:
data->scenery.elevator.type = proto->scenery.data.elevator.type;
data->scenery.elevator.level = proto->scenery.data.elevator.level;
2022-05-19 01:51:26 -07:00
break;
case SCENERY_TYPE_LADDER_UP:
case SCENERY_TYPE_LADDER_DOWN:
data->scenery.ladder.destinationMap = proto->scenery.data.ladder.field_0;
2022-05-19 01:51:26 -07:00
break;
}
break;
case OBJ_TYPE_MISC:
2022-12-13 03:34:49 -08:00
if (isExitGridPid(obj->pid)) {
2022-05-19 01:51:26 -07:00
data->misc.tile = -1;
data->misc.elevation = 0;
data->misc.rotation = 0;
data->misc.map = -1;
}
break;
default:
break;
}
return 0;
}
// 0x49F8A0
int _proto_update_init(Object* obj)
{
if (!_protos_been_initialized) {
return -1;
}
if (obj == NULL) {
return -1;
}
if (obj->pid == -1) {
return -1;
}
for (int i = 0; i < 14; i++) {
obj->field_2C_array[i] = 0;
}
if (PID_TYPE(obj->pid) != OBJ_TYPE_CRITTER) {
2022-05-19 01:51:26 -07:00
return _proto_update_gen(obj);
}
ObjectData* data = &(obj->data);
data->inventory.length = 0;
data->inventory.capacity = 0;
data->inventory.items = NULL;
_combat_data_init(obj);
data->critter.hp = critterGetStat(obj, STAT_MAXIMUM_HIT_POINTS);
data->critter.combat.ap = critterGetStat(obj, STAT_MAXIMUM_ACTION_POINTS);
critterUpdateDerivedStats(obj);
obj->data.critter.combat.whoHitMe = NULL;
Proto* proto;
if (protoGetProto(obj->pid, &proto) != -1) {
data->critter.combat.aiPacket = proto->critter.aiPacket;
data->critter.combat.team = proto->critter.team;
}
return 0;
}
// 0x49F984
int _proto_dude_update_gender()
{
Proto* proto;
if (protoGetProto(0x1000000, &proto) == -1) {
return -1;
}
int nativeLook = DUDE_NATIVE_LOOK_TRIBAL;
if (gameMovieIsSeen(MOVIE_VSUIT)) {
nativeLook = DUDE_NATIVE_LOOK_JUMPSUIT;
}
int frmId;
if (critterGetStat(gDude, STAT_GENDER) == GENDER_MALE) {
frmId = _art_vault_person_nums[nativeLook][GENDER_MALE];
} else {
frmId = _art_vault_person_nums[nativeLook][GENDER_FEMALE];
}
_art_vault_guy_num = frmId;
if (critterGetArmor(gDude) == NULL) {
int v1 = 0;
if (critterGetItem2(gDude) != NULL || critterGetItem1(gDude) != NULL) {
v1 = (gDude->fid & 0xF000) >> 12;
}
int fid = buildFid(OBJ_TYPE_CRITTER, _art_vault_guy_num, 0, v1, 0);
2022-05-19 01:51:26 -07:00
objectSetFid(gDude, fid, NULL);
}
proto->fid = buildFid(OBJ_TYPE_CRITTER, _art_vault_guy_num, 0, 0, 0);
2022-05-19 01:51:26 -07:00
return 0;
}
// proto_dude_init
// 0x49FA64
int _proto_dude_init(const char* path)
{
gDudeProto.fid = buildFid(OBJ_TYPE_CRITTER, _art_vault_guy_num, 0, 0, 0);
2022-05-19 01:51:26 -07:00
if (_init_true) {
_obj_inven_free(&(gDude->data.inventory));
}
_init_true = 1;
Proto* proto;
if (protoGetProto(0x1000000, &proto) == -1) {
return -1;
}
protoGetProto(gDude->pid, &proto);
_proto_update_init(gDude);
gDude->data.critter.combat.aiPacket = 0;
gDude->data.critter.combat.team = 0;
_ResetPlayer();
if (gcdLoad(path) == -1) {
_retval = -1;
}
proto->critter.data.baseStats[STAT_DAMAGE_RESISTANCE_EMP] = 100;
proto->critter.data.bodyType = 0;
proto->critter.data.experience = 0;
proto->critter.data.killType = 0;
proto->critter.data.damageType = 0;
_proto_dude_update_gender();
_inven_reset_dude();
if ((gDude->flags & OBJECT_FLAT) != 0) {
2022-05-19 01:51:26 -07:00
_obj_toggle_flat(gDude, NULL);
}
if ((gDude->flags & OBJECT_NO_BLOCK) != 0) {
gDude->flags &= ~OBJECT_NO_BLOCK;
}
critterUpdateDerivedStats(gDude);
critterAdjustHitPoints(gDude, 10000);
if (_retval) {
debugPrint("\n ** Error in proto_dude_init()! **\n");
}
return 0;
}
2023-07-22 04:46:51 -07:00
// 0x49FEDC
bool proto_is_subtype(Proto* proto, int subtype)
{
if (subtype == -1) {
return true;
}
switch (PID_TYPE(proto->pid)) {
case OBJ_TYPE_ITEM:
return proto->item.type == subtype;
case OBJ_TYPE_SCENERY:
return proto->scenery.type == subtype;
}
return false;
}
2022-05-19 01:51:26 -07:00
// proto_data_member
// 0x49FFD8
int protoGetDataMember(int pid, int member, ProtoDataMemberValue* value)
2022-05-19 01:51:26 -07:00
{
Proto* proto;
if (protoGetProto(pid, &proto) == -1) {
return -1;
}
switch (PID_TYPE(pid)) {
2022-05-19 01:51:26 -07:00
case OBJ_TYPE_ITEM:
switch (member) {
case ITEM_DATA_MEMBER_PID:
value->integerValue = proto->pid;
2022-05-19 01:51:26 -07:00
break;
case ITEM_DATA_MEMBER_NAME:
// NOTE: uninline
value->stringValue = protoGetName(proto->scenery.pid);
2022-05-19 01:51:26 -07:00
return PROTO_DATA_MEMBER_TYPE_STRING;
case ITEM_DATA_MEMBER_DESCRIPTION:
// NOTE: Uninline.
value->stringValue = protoGetDescription(proto->pid);
2022-05-19 01:51:26 -07:00
return PROTO_DATA_MEMBER_TYPE_STRING;
case ITEM_DATA_MEMBER_FID:
value->integerValue = proto->fid;
2022-05-19 01:51:26 -07:00
break;
case ITEM_DATA_MEMBER_LIGHT_DISTANCE:
value->integerValue = proto->item.lightDistance;
2022-05-19 01:51:26 -07:00
break;
case ITEM_DATA_MEMBER_LIGHT_INTENSITY:
value->integerValue = proto->item.lightIntensity;
2022-05-19 01:51:26 -07:00
break;
case ITEM_DATA_MEMBER_FLAGS:
value->integerValue = proto->item.flags;
2022-05-19 01:51:26 -07:00
break;
case ITEM_DATA_MEMBER_EXTENDED_FLAGS:
value->integerValue = proto->item.extendedFlags;
2022-05-19 01:51:26 -07:00
break;
case ITEM_DATA_MEMBER_SID:
value->integerValue = proto->item.sid;
2022-05-19 01:51:26 -07:00
break;
case ITEM_DATA_MEMBER_TYPE:
value->integerValue = proto->item.type;
2022-05-19 01:51:26 -07:00
break;
case ITEM_DATA_MEMBER_MATERIAL:
value->integerValue = proto->item.material;
2022-05-19 01:51:26 -07:00
break;
case ITEM_DATA_MEMBER_SIZE:
value->integerValue = proto->item.size;
2022-05-19 01:51:26 -07:00
break;
case ITEM_DATA_MEMBER_WEIGHT:
value->integerValue = proto->item.weight;
2022-05-19 01:51:26 -07:00
break;
case ITEM_DATA_MEMBER_COST:
value->integerValue = proto->item.cost;
2022-05-19 01:51:26 -07:00
break;
case ITEM_DATA_MEMBER_INVENTORY_FID:
value->integerValue = proto->item.inventoryFid;
2022-05-19 01:51:26 -07:00
break;
case ITEM_DATA_MEMBER_WEAPON_RANGE:
if (proto->item.type == ITEM_TYPE_WEAPON) {
value->integerValue = proto->item.data.weapon.maxRange1;
2022-05-19 01:51:26 -07:00
}
break;
default:
debugPrint("\n\tError: Unimp'd data member in member in proto_data_member!");
break;
}
break;
case OBJ_TYPE_CRITTER:
switch (member) {
case CRITTER_DATA_MEMBER_PID:
value->integerValue = proto->critter.pid;
2022-05-19 01:51:26 -07:00
break;
case CRITTER_DATA_MEMBER_NAME:
// NOTE: Uninline.
value->stringValue = protoGetName(proto->critter.pid);
2022-05-19 01:51:26 -07:00
return PROTO_DATA_MEMBER_TYPE_STRING;
case CRITTER_DATA_MEMBER_DESCRIPTION:
// NOTE: Uninline.
value->stringValue = protoGetDescription(proto->critter.pid);
2022-05-19 01:51:26 -07:00
return PROTO_DATA_MEMBER_TYPE_STRING;
case CRITTER_DATA_MEMBER_FID:
value->integerValue = proto->critter.fid;
2022-05-19 01:51:26 -07:00
break;
case CRITTER_DATA_MEMBER_LIGHT_DISTANCE:
value->integerValue = proto->critter.lightDistance;
2022-05-19 01:51:26 -07:00
break;
case CRITTER_DATA_MEMBER_LIGHT_INTENSITY:
value->integerValue = proto->critter.lightIntensity;
2022-05-19 01:51:26 -07:00
break;
case CRITTER_DATA_MEMBER_FLAGS:
value->integerValue = proto->critter.flags;
2022-05-19 01:51:26 -07:00
break;
case CRITTER_DATA_MEMBER_EXTENDED_FLAGS:
value->integerValue = proto->critter.extendedFlags;
2022-05-19 01:51:26 -07:00
break;
case CRITTER_DATA_MEMBER_SID:
value->integerValue = proto->critter.sid;
2022-05-19 01:51:26 -07:00
break;
case CRITTER_DATA_MEMBER_HEAD_FID:
value->integerValue = proto->critter.headFid;
2022-05-19 01:51:26 -07:00
break;
case CRITTER_DATA_MEMBER_BODY_TYPE:
value->integerValue = proto->critter.data.bodyType;
2022-05-19 01:51:26 -07:00
break;
default:
debugPrint("\n\tError: Unimp'd data member in member in proto_data_member!");
break;
}
break;
case OBJ_TYPE_SCENERY:
switch (member) {
case SCENERY_DATA_MEMBER_PID:
value->integerValue = proto->scenery.pid;
2022-05-19 01:51:26 -07:00
break;
case SCENERY_DATA_MEMBER_NAME:
// NOTE: Uninline.
value->stringValue = protoGetName(proto->scenery.pid);
2022-05-19 01:51:26 -07:00
return PROTO_DATA_MEMBER_TYPE_STRING;
case SCENERY_DATA_MEMBER_DESCRIPTION:
// NOTE: Uninline.
value->stringValue = protoGetDescription(proto->scenery.pid);
2022-05-19 01:51:26 -07:00
return PROTO_DATA_MEMBER_TYPE_STRING;
case SCENERY_DATA_MEMBER_FID:
value->integerValue = proto->scenery.fid;
2022-05-19 01:51:26 -07:00
break;
case SCENERY_DATA_MEMBER_LIGHT_DISTANCE:
value->integerValue = proto->scenery.lightDistance;
2022-05-19 01:51:26 -07:00
break;
case SCENERY_DATA_MEMBER_LIGHT_INTENSITY:
value->integerValue = proto->scenery.lightIntensity;
2022-05-19 01:51:26 -07:00
break;
case SCENERY_DATA_MEMBER_FLAGS:
value->integerValue = proto->scenery.flags;
2022-05-19 01:51:26 -07:00
break;
case SCENERY_DATA_MEMBER_EXTENDED_FLAGS:
value->integerValue = proto->scenery.extendedFlags;
2022-05-19 01:51:26 -07:00
break;
case SCENERY_DATA_MEMBER_SID:
value->integerValue = proto->scenery.sid;
2022-05-19 01:51:26 -07:00
break;
case SCENERY_DATA_MEMBER_TYPE:
value->integerValue = proto->scenery.type;
2022-05-19 01:51:26 -07:00
break;
case SCENERY_DATA_MEMBER_MATERIAL:
value->integerValue = proto->scenery.field_2C;
2022-05-19 01:51:26 -07:00
break;
default:
debugPrint("\n\tError: Unimp'd data member in member in proto_data_member!");
break;
}
break;
case OBJ_TYPE_WALL:
switch (member) {
case WALL_DATA_MEMBER_PID:
value->integerValue = proto->wall.pid;
2022-05-19 01:51:26 -07:00
break;
case WALL_DATA_MEMBER_NAME:
// NOTE: Uninline.
value->stringValue = protoGetName(proto->wall.pid);
2022-05-19 01:51:26 -07:00
return PROTO_DATA_MEMBER_TYPE_STRING;
case WALL_DATA_MEMBER_DESCRIPTION:
// NOTE: Uninline.
value->stringValue = protoGetDescription(proto->wall.pid);
2022-05-19 01:51:26 -07:00
return PROTO_DATA_MEMBER_TYPE_STRING;
case WALL_DATA_MEMBER_FID:
value->integerValue = proto->wall.fid;
2022-05-19 01:51:26 -07:00
break;
case WALL_DATA_MEMBER_LIGHT_DISTANCE:
value->integerValue = proto->wall.lightDistance;
2022-05-19 01:51:26 -07:00
break;
case WALL_DATA_MEMBER_LIGHT_INTENSITY:
value->integerValue = proto->wall.lightIntensity;
2022-05-19 01:51:26 -07:00
break;
case WALL_DATA_MEMBER_FLAGS:
value->integerValue = proto->wall.flags;
2022-05-19 01:51:26 -07:00
break;
case WALL_DATA_MEMBER_EXTENDED_FLAGS:
value->integerValue = proto->wall.extendedFlags;
2022-05-19 01:51:26 -07:00
break;
case WALL_DATA_MEMBER_SID:
value->integerValue = proto->wall.sid;
2022-05-19 01:51:26 -07:00
break;
case WALL_DATA_MEMBER_MATERIAL:
value->integerValue = proto->wall.material;
2022-05-19 01:51:26 -07:00
break;
default:
debugPrint("\n\tError: Unimp'd data member in member in proto_data_member!");
break;
}
break;
case OBJ_TYPE_TILE:
debugPrint("\n\tError: Unimp'd data member in member in proto_data_member!");
break;
case OBJ_TYPE_MISC:
switch (member) {
case MISC_DATA_MEMBER_PID:
value->integerValue = proto->misc.pid;
2022-05-19 01:51:26 -07:00
break;
case MISC_DATA_MEMBER_NAME:
// NOTE: Uninline.
value->stringValue = protoGetName(proto->misc.pid);
2022-05-19 01:51:26 -07:00
return PROTO_DATA_MEMBER_TYPE_STRING;
case MISC_DATA_MEMBER_DESCRIPTION:
// NOTE: Uninline.
value->stringValue = protoGetDescription(proto->misc.pid);
2022-05-19 01:51:26 -07:00
// FIXME: Errornously report type as int, should be string.
return PROTO_DATA_MEMBER_TYPE_INT;
case MISC_DATA_MEMBER_FID:
value->integerValue = proto->misc.fid;
2022-05-19 01:51:26 -07:00
return 1;
case MISC_DATA_MEMBER_LIGHT_DISTANCE:
value->integerValue = proto->misc.lightDistance;
2022-05-19 01:51:26 -07:00
return 1;
case MISC_DATA_MEMBER_LIGHT_INTENSITY:
value->integerValue = proto->misc.lightIntensity;
2022-05-19 01:51:26 -07:00
break;
case MISC_DATA_MEMBER_FLAGS:
value->integerValue = proto->misc.flags;
2022-05-19 01:51:26 -07:00
break;
case MISC_DATA_MEMBER_EXTENDED_FLAGS:
value->integerValue = proto->misc.extendedFlags;
2022-05-19 01:51:26 -07:00
break;
default:
debugPrint("\n\tError: Unimp'd data member in member in proto_data_member!");
break;
}
break;
}
return PROTO_DATA_MEMBER_TYPE_INT;
}
// proto_init
// 0x4A0390
int protoInit()
{
2022-08-31 08:52:01 -07:00
size_t len;
2022-05-19 01:51:26 -07:00
MessageListItem messageListItem;
2022-05-28 02:34:49 -07:00
char path[COMPAT_MAX_PATH];
2022-05-19 01:51:26 -07:00
int i;
2022-12-08 12:05:50 -08:00
snprintf(path, sizeof(path), "%s\\proto", settings.system.master_patches_path.c_str());
2022-05-19 01:51:26 -07:00
len = strlen(path);
compat_mkdir(path);
2022-05-19 01:51:26 -07:00
strcpy(path + len, "\\critters");
compat_mkdir(path);
2022-05-19 01:51:26 -07:00
strcpy(path + len, "\\items");
compat_mkdir(path);
2022-05-19 01:51:26 -07:00
// TODO: Get rid of cast.
_proto_critter_init((Proto*)&gDudeProto, 0x1000000);
gDudeProto.pid = 0x1000000;
gDudeProto.fid = buildFid(OBJ_TYPE_CRITTER, 1, 0, 0, 0);
2022-05-19 01:51:26 -07:00
gDude->pid = 0x1000000;
gDude->sid = 1;
for (i = 0; i < 6; i++) {
_proto_remove_list(i);
}
_proto_header_load();
_protos_been_initialized = 1;
_proto_dude_init("premade\\player.gcd");
for (i = 0; i < 6; i++) {
if (!messageListInit(&(_proto_msg_files[i]))) {
debugPrint("\nError: Initing proto message files!");
return -1;
}
}
for (i = 0; i < 6; i++) {
2022-12-08 12:05:50 -08:00
snprintf(path, sizeof(path), "%spro_%.4s%s", asc_5186C8, artGetObjectTypeName(i), ".msg");
2022-05-19 01:51:26 -07:00
if (!messageListLoad(&(_proto_msg_files[i]), path)) {
debugPrint("\nError: Loading proto message files!");
return -1;
}
}
for (i = 0; i < 6; i++) {
messageListRepositorySetProtoMessageList(i, &(_proto_msg_files[i]));
}
2022-05-19 01:51:26 -07:00
_mp_critter_stats_list = _aDrugStatSpecia;
_critter_stats_list = _critter_stats_list_strs;
_critter_stats_list_None = _aNone_1;
for (i = 0; i < STAT_COUNT; i++) {
_critter_stats_list_strs[i] = statGetName(i);
if (_critter_stats_list_strs[i] == NULL) {
debugPrint("\nError: Finding stat names!");
return -1;
}
}
_mp_perk_code_None = _aNone_1;
_perk_code_strs = _mp_perk_code_strs;
for (i = 0; i < PERK_COUNT; i++) {
_mp_perk_code_strs[i] = perkGetName(i);
if (_mp_perk_code_strs[i] == NULL) {
debugPrint("\nError: Finding perk names!");
return -1;
}
}
if (!messageListInit(&gProtoMessageList)) {
debugPrint("\nError: Initing main proto message file!");
return -1;
}
2022-12-08 12:05:50 -08:00
snprintf(path, sizeof(path), "%sproto.msg", asc_5186C8);
2022-05-19 01:51:26 -07:00
if (!messageListLoad(&gProtoMessageList, path)) {
debugPrint("\nError: Loading main proto message file!");
return -1;
}
_proto_none_str = getmsg(&gProtoMessageList, &messageListItem, 10);
// material type names
for (i = 0; i < MATERIAL_TYPE_COUNT; i++) {
gMaterialTypeNames[i] = getmsg(&gProtoMessageList, &messageListItem, 100 + i);
}
// item type names
for (i = 0; i < ITEM_TYPE_COUNT; i++) {
gItemTypeNames[i] = getmsg(&gProtoMessageList, &messageListItem, 150 + i);
}
// scenery type names
for (i = 0; i < SCENERY_TYPE_COUNT; i++) {
gSceneryTypeNames[i] = getmsg(&gProtoMessageList, &messageListItem, 200 + i);
}
// damage code types
for (i = 0; i < DAMAGE_TYPE_COUNT; i++) {
gDamageTypeNames[i] = getmsg(&gProtoMessageList, &messageListItem, 250 + i);
}
// caliber types
for (i = 0; i < CALIBER_TYPE_COUNT; i++) {
gCaliberTypeNames[i] = getmsg(&gProtoMessageList, &messageListItem, 300 + i);
}
// race types
for (i = 0; i < RACE_TYPE_COUNT; i++) {
gRaceTypeNames[i] = getmsg(&gProtoMessageList, &messageListItem, 350 + i);
}
// body types
for (i = 0; i < BODY_TYPE_COUNT; i++) {
gBodyTypeNames[i] = getmsg(&gProtoMessageList, &messageListItem, 400 + i);
}
messageListRepositorySetStandardMessageList(STANDARD_MESSAGE_LIST_PROTO, &gProtoMessageList);
2022-05-19 01:51:26 -07:00
return 0;
}
// 0x4A0814
void protoReset()
{
int i;
// TODO: Get rid of cast.
_proto_critter_init((Proto*)&gDudeProto, 0x1000000);
gDudeProto.pid = 0x1000000;
gDudeProto.fid = buildFid(OBJ_TYPE_CRITTER, 1, 0, 0, 0);
2022-05-19 01:51:26 -07:00
gDude->pid = 0x1000000;
gDude->sid = -1;
gDude->flags &= ~OBJECT_FLAG_0xFC000;
for (i = 0; i < 6; i++) {
_proto_remove_list(i);
}
_proto_header_load();
_protos_been_initialized = 1;
_proto_dude_init("premade\\player.gcd");
}
// 0x4A0898
void protoExit()
{
int i;
for (i = 0; i < 6; i++) {
_proto_remove_list(i);
}
for (i = 0; i < 6; i++) {
messageListRepositorySetProtoMessageList(i, nullptr);
2022-05-19 01:51:26 -07:00
messageListFree(&(_proto_msg_files[i]));
}
messageListRepositorySetStandardMessageList(STANDARD_MESSAGE_LIST_PROTO, nullptr);
2022-05-19 01:51:26 -07:00
messageListFree(&gProtoMessageList);
}
// Count .pro lines in .lst files.
//
// 0x4A08E0
2022-06-19 04:42:07 -07:00
static int _proto_header_load()
2022-05-19 01:51:26 -07:00
{
for (int index = 0; index < 6; index++) {
ProtoList* ptr = &(_protoLists[index]);
ptr->head = NULL;
ptr->tail = NULL;
ptr->length = 0;
ptr->max_entries_num = 1;
2022-05-28 02:34:49 -07:00
char path[COMPAT_MAX_PATH];
_proto_make_path(path, index << 24);
2022-05-19 01:51:26 -07:00
strcat(path, "\\");
strcat(path, artGetObjectTypeName(index));
strcat(path, ".lst");
File* stream = fileOpen(path, "rt");
if (stream == NULL) {
return -1;
}
int ch = '\0';
while (1) {
ch = fileReadChar(stream);
if (ch == -1) {
break;
}
if (ch == '\n') {
ptr->max_entries_num++;
}
}
if (ch != '\n') {
ptr->max_entries_num++;
}
fileClose(stream);
}
return 0;
}
// 0x4A0AEC
2022-06-19 04:42:07 -07:00
static int protoItemDataRead(ItemProtoData* item_data, int type, File* stream)
2022-05-19 01:51:26 -07:00
{
switch (type) {
case ITEM_TYPE_ARMOR:
if (fileReadInt32(stream, &(item_data->armor.armorClass)) == -1) return -1;
if (fileReadInt32List(stream, item_data->armor.damageResistance, 7) == -1) return -1;
if (fileReadInt32List(stream, item_data->armor.damageThreshold, 7) == -1) return -1;
if (fileReadInt32(stream, &(item_data->armor.perk)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->armor.maleFid)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->armor.femaleFid)) == -1) return -1;
return 0;
case ITEM_TYPE_CONTAINER:
if (fileReadInt32(stream, &(item_data->container.maxSize)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->container.openFlags)) == -1) return -1;
return 0;
case ITEM_TYPE_DRUG:
if (fileReadInt32(stream, &(item_data->drug.stat[0])) == -1) return -1;
if (fileReadInt32(stream, &(item_data->drug.stat[1])) == -1) return -1;
if (fileReadInt32(stream, &(item_data->drug.stat[2])) == -1) return -1;
if (fileReadInt32List(stream, item_data->drug.amount, 3) == -1) return -1;
if (fileReadInt32(stream, &(item_data->drug.duration1)) == -1) return -1;
if (fileReadInt32List(stream, item_data->drug.amount1, 3) == -1) return -1;
if (fileReadInt32(stream, &(item_data->drug.duration2)) == -1) return -1;
if (fileReadInt32List(stream, item_data->drug.amount2, 3) == -1) return -1;
if (fileReadInt32(stream, &(item_data->drug.addictionChance)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->drug.withdrawalEffect)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->drug.withdrawalOnset)) == -1) return -1;
return 0;
case ITEM_TYPE_WEAPON:
if (fileReadInt32(stream, &(item_data->weapon.animationCode)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->weapon.minDamage)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->weapon.maxDamage)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->weapon.damageType)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->weapon.maxRange1)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->weapon.maxRange2)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->weapon.projectilePid)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->weapon.minStrength)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->weapon.actionPointCost1)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->weapon.actionPointCost2)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->weapon.criticalFailureType)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->weapon.perk)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->weapon.rounds)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->weapon.caliber)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->weapon.ammoTypePid)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->weapon.ammoCapacity)) == -1) return -1;
if (fileReadUInt8(stream, &(item_data->weapon.soundCode)) == -1) return -1;
return 0;
case ITEM_TYPE_AMMO:
if (fileReadInt32(stream, &(item_data->ammo.caliber)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->ammo.quantity)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->ammo.armorClassModifier)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->ammo.damageResistanceModifier)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->ammo.damageMultiplier)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->ammo.damageDivisor)) == -1) return -1;
return 0;
case ITEM_TYPE_MISC:
if (fileReadInt32(stream, &(item_data->misc.powerTypePid)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->misc.powerType)) == -1) return -1;
if (fileReadInt32(stream, &(item_data->misc.charges)) == -1) return -1;
return 0;
case ITEM_TYPE_KEY:
if (fileReadInt32(stream, &(item_data->key.keyCode)) == -1) return -1;
return 0;
}
return 0;
}
// 0x4A0ED0
2022-06-19 04:42:07 -07:00
static int protoSceneryDataRead(SceneryProtoData* scenery_data, int type, File* stream)
2022-05-19 01:51:26 -07:00
{
switch (type) {
case SCENERY_TYPE_DOOR:
if (fileReadInt32(stream, &(scenery_data->door.openFlags)) == -1) return -1;
if (fileReadInt32(stream, &(scenery_data->door.keyCode)) == -1) return -1;
return 0;
case SCENERY_TYPE_STAIRS:
if (fileReadInt32(stream, &(scenery_data->stairs.field_0)) == -1) return -1;
if (fileReadInt32(stream, &(scenery_data->stairs.field_4)) == -1) return -1;
return 0;
case SCENERY_TYPE_ELEVATOR:
if (fileReadInt32(stream, &(scenery_data->elevator.type)) == -1) return -1;
if (fileReadInt32(stream, &(scenery_data->elevator.level)) == -1) return -1;
2022-05-19 01:51:26 -07:00
return 0;
case SCENERY_TYPE_LADDER_UP:
case SCENERY_TYPE_LADDER_DOWN:
if (fileReadInt32(stream, &(scenery_data->ladder.field_0)) == -1) return -1;
return 0;
case SCENERY_TYPE_GENERIC:
if (fileReadInt32(stream, &(scenery_data->generic.field_0)) == -1) return -1;
return 0;
}
return 0;
}
// read .pro file
// 0x4A0FA0
2022-06-19 04:42:07 -07:00
static int protoRead(Proto* proto, File* stream)
2022-05-19 01:51:26 -07:00
{
if (fileReadInt32(stream, &(proto->pid)) == -1) return -1;
if (fileReadInt32(stream, &(proto->messageId)) == -1) return -1;
if (fileReadInt32(stream, &(proto->fid)) == -1) return -1;
switch (PID_TYPE(proto->pid)) {
2022-05-19 01:51:26 -07:00
case OBJ_TYPE_ITEM:
if (fileReadInt32(stream, &(proto->item.lightDistance)) == -1) return -1;
if (_db_freadInt(stream, &(proto->item.lightIntensity)) == -1) return -1;
if (fileReadInt32(stream, &(proto->item.flags)) == -1) return -1;
if (fileReadInt32(stream, &(proto->item.extendedFlags)) == -1) return -1;
if (fileReadInt32(stream, &(proto->item.sid)) == -1) return -1;
if (fileReadInt32(stream, &(proto->item.type)) == -1) return -1;
if (fileReadInt32(stream, &(proto->item.material)) == -1) return -1;
if (fileReadInt32(stream, &(proto->item.size)) == -1) return -1;
if (_db_freadInt(stream, &(proto->item.weight)) == -1) return -1;
if (fileReadInt32(stream, &(proto->item.cost)) == -1) return -1;
if (fileReadInt32(stream, &(proto->item.inventoryFid)) == -1) return -1;
if (fileReadUInt8(stream, &(proto->item.field_80)) == -1) return -1;
if (protoItemDataRead(&(proto->item.data), proto->item.type, stream) == -1) return -1;
return 0;
case OBJ_TYPE_CRITTER:
if (fileReadInt32(stream, &(proto->critter.lightDistance)) == -1) return -1;
if (_db_freadInt(stream, &(proto->critter.lightIntensity)) == -1) return -1;
if (fileReadInt32(stream, &(proto->critter.flags)) == -1) return -1;
if (fileReadInt32(stream, &(proto->critter.extendedFlags)) == -1) return -1;
if (fileReadInt32(stream, &(proto->critter.sid)) == -1) return -1;
if (fileReadInt32(stream, &(proto->critter.headFid)) == -1) return -1;
if (fileReadInt32(stream, &(proto->critter.aiPacket)) == -1) return -1;
if (fileReadInt32(stream, &(proto->critter.team)) == -1) return -1;
if (protoCritterDataRead(stream, &(proto->critter.data)) == -1) return -1;
return 0;
case OBJ_TYPE_SCENERY:
if (fileReadInt32(stream, &(proto->scenery.lightDistance)) == -1) return -1;
if (_db_freadInt(stream, &(proto->scenery.lightIntensity)) == -1) return -1;
if (fileReadInt32(stream, &(proto->scenery.flags)) == -1) return -1;
if (fileReadInt32(stream, &(proto->scenery.extendedFlags)) == -1) return -1;
if (fileReadInt32(stream, &(proto->scenery.sid)) == -1) return -1;
if (fileReadInt32(stream, &(proto->scenery.type)) == -1) return -1;
if (fileReadInt32(stream, &(proto->scenery.field_2C)) == -1) return -1;
if (fileReadUInt8(stream, &(proto->scenery.field_34)) == -1) return -1;
if (protoSceneryDataRead(&(proto->scenery.data), proto->scenery.type, stream) == -1) return -1;
return 0;
case OBJ_TYPE_WALL:
if (fileReadInt32(stream, &(proto->wall.lightDistance)) == -1) return -1;
if (_db_freadInt(stream, &(proto->wall.lightIntensity)) == -1) return -1;
if (fileReadInt32(stream, &(proto->wall.flags)) == -1) return -1;
if (fileReadInt32(stream, &(proto->wall.extendedFlags)) == -1) return -1;
if (fileReadInt32(stream, &(proto->wall.sid)) == -1) return -1;
if (fileReadInt32(stream, &(proto->wall.material)) == -1) return -1;
return 0;
case OBJ_TYPE_TILE:
if (fileReadInt32(stream, &(proto->tile.flags)) == -1) return -1;
if (fileReadInt32(stream, &(proto->tile.extendedFlags)) == -1) return -1;
if (fileReadInt32(stream, &(proto->tile.sid)) == -1) return -1;
if (fileReadInt32(stream, &(proto->tile.material)) == -1) return -1;
return 0;
case OBJ_TYPE_MISC:
if (fileReadInt32(stream, &(proto->misc.lightDistance)) == -1) return -1;
if (_db_freadInt(stream, &(proto->misc.lightIntensity)) == -1) return -1;
if (fileReadInt32(stream, &(proto->misc.flags)) == -1) return -1;
if (fileReadInt32(stream, &(proto->misc.extendedFlags)) == -1) return -1;
return 0;
}
return -1;
}
// 0x4A1390
2022-06-19 04:42:07 -07:00
static int protoItemDataWrite(ItemProtoData* item_data, int type, File* stream)
2022-05-19 01:51:26 -07:00
{
switch (type) {
case ITEM_TYPE_ARMOR:
if (fileWriteInt32(stream, item_data->armor.armorClass) == -1) return -1;
if (fileWriteInt32List(stream, item_data->armor.damageResistance, 7) == -1) return -1;
if (fileWriteInt32List(stream, item_data->armor.damageThreshold, 7) == -1) return -1;
if (fileWriteInt32(stream, item_data->armor.perk) == -1) return -1;
if (fileWriteInt32(stream, item_data->armor.maleFid) == -1) return -1;
if (fileWriteInt32(stream, item_data->armor.femaleFid) == -1) return -1;
return 0;
case ITEM_TYPE_CONTAINER:
if (fileWriteInt32(stream, item_data->container.maxSize) == -1) return -1;
if (fileWriteInt32(stream, item_data->container.openFlags) == -1) return -1;
return 0;
case ITEM_TYPE_DRUG:
if (fileWriteInt32(stream, item_data->drug.stat[0]) == -1) return -1;
if (fileWriteInt32(stream, item_data->drug.stat[1]) == -1) return -1;
if (fileWriteInt32(stream, item_data->drug.stat[2]) == -1) return -1;
if (fileWriteInt32List(stream, item_data->drug.amount, 3) == -1) return -1;
if (fileWriteInt32(stream, item_data->drug.duration1) == -1) return -1;
if (fileWriteInt32List(stream, item_data->drug.amount1, 3) == -1) return -1;
if (fileWriteInt32(stream, item_data->drug.duration2) == -1) return -1;
if (fileWriteInt32List(stream, item_data->drug.amount2, 3) == -1) return -1;
if (fileWriteInt32(stream, item_data->drug.addictionChance) == -1) return -1;
if (fileWriteInt32(stream, item_data->drug.withdrawalEffect) == -1) return -1;
if (fileWriteInt32(stream, item_data->drug.withdrawalOnset) == -1) return -1;
return 0;
case ITEM_TYPE_WEAPON:
if (fileWriteInt32(stream, item_data->weapon.animationCode) == -1) return -1;
if (fileWriteInt32(stream, item_data->weapon.maxDamage) == -1) return -1;
if (fileWriteInt32(stream, item_data->weapon.minDamage) == -1) return -1;
if (fileWriteInt32(stream, item_data->weapon.damageType) == -1) return -1;
if (fileWriteInt32(stream, item_data->weapon.maxRange1) == -1) return -1;
if (fileWriteInt32(stream, item_data->weapon.maxRange2) == -1) return -1;
if (fileWriteInt32(stream, item_data->weapon.projectilePid) == -1) return -1;
if (fileWriteInt32(stream, item_data->weapon.minStrength) == -1) return -1;
if (fileWriteInt32(stream, item_data->weapon.actionPointCost1) == -1) return -1;
if (fileWriteInt32(stream, item_data->weapon.actionPointCost2) == -1) return -1;
if (fileWriteInt32(stream, item_data->weapon.criticalFailureType) == -1) return -1;
if (fileWriteInt32(stream, item_data->weapon.perk) == -1) return -1;
if (fileWriteInt32(stream, item_data->weapon.rounds) == -1) return -1;
if (fileWriteInt32(stream, item_data->weapon.caliber) == -1) return -1;
if (fileWriteInt32(stream, item_data->weapon.ammoTypePid) == -1) return -1;
if (fileWriteInt32(stream, item_data->weapon.ammoCapacity) == -1) return -1;
if (fileWriteUInt8(stream, item_data->weapon.soundCode) == -1) return -1;
return 0;
case ITEM_TYPE_AMMO:
if (fileWriteInt32(stream, item_data->ammo.caliber) == -1) return -1;
if (fileWriteInt32(stream, item_data->ammo.quantity) == -1) return -1;
if (fileWriteInt32(stream, item_data->ammo.armorClassModifier) == -1) return -1;
if (fileWriteInt32(stream, item_data->ammo.damageResistanceModifier) == -1) return -1;
if (fileWriteInt32(stream, item_data->ammo.damageMultiplier) == -1) return -1;
if (fileWriteInt32(stream, item_data->ammo.damageDivisor) == -1) return -1;
return 0;
case ITEM_TYPE_MISC:
if (fileWriteInt32(stream, item_data->misc.powerTypePid) == -1) return -1;
if (fileWriteInt32(stream, item_data->misc.powerType) == -1) return -1;
if (fileWriteInt32(stream, item_data->misc.charges) == -1) return -1;
return 0;
case ITEM_TYPE_KEY:
if (fileWriteInt32(stream, item_data->key.keyCode) == -1) return -1;
return 0;
}
return 0;
}
// 0x4A16E4
2022-06-19 04:42:07 -07:00
static int protoSceneryDataWrite(SceneryProtoData* scenery_data, int type, File* stream)
2022-05-19 01:51:26 -07:00
{
switch (type) {
case SCENERY_TYPE_DOOR:
if (fileWriteInt32(stream, scenery_data->door.openFlags) == -1) return -1;
if (fileWriteInt32(stream, scenery_data->door.keyCode) == -1) return -1;
return 0;
case SCENERY_TYPE_STAIRS:
if (fileWriteInt32(stream, scenery_data->stairs.field_0) == -1) return -1;
if (fileWriteInt32(stream, scenery_data->stairs.field_4) == -1) return -1;
return 0;
case SCENERY_TYPE_ELEVATOR:
if (fileWriteInt32(stream, scenery_data->elevator.type) == -1) return -1;
if (fileWriteInt32(stream, scenery_data->elevator.level) == -1) return -1;
2022-05-19 01:51:26 -07:00
return 0;
case SCENERY_TYPE_LADDER_UP:
case SCENERY_TYPE_LADDER_DOWN:
if (fileWriteInt32(stream, scenery_data->ladder.field_0) == -1) return -1;
return 0;
case SCENERY_TYPE_GENERIC:
if (fileWriteInt32(stream, scenery_data->generic.field_0) == -1) return -1;
return 0;
}
return 0;
}
// 0x4A17B4
2022-06-19 04:42:07 -07:00
static int protoWrite(Proto* proto, File* stream)
2022-05-19 01:51:26 -07:00
{
if (fileWriteInt32(stream, proto->pid) == -1) return -1;
if (fileWriteInt32(stream, proto->messageId) == -1) return -1;
if (fileWriteInt32(stream, proto->fid) == -1) return -1;
switch (PID_TYPE(proto->pid)) {
2022-05-19 01:51:26 -07:00
case OBJ_TYPE_ITEM:
if (fileWriteInt32(stream, proto->item.lightDistance) == -1) return -1;
if (_db_fwriteLong(stream, proto->item.lightIntensity) == -1) return -1;
if (fileWriteInt32(stream, proto->item.flags) == -1) return -1;
if (fileWriteInt32(stream, proto->item.extendedFlags) == -1) return -1;
if (fileWriteInt32(stream, proto->item.sid) == -1) return -1;
if (fileWriteInt32(stream, proto->item.type) == -1) return -1;
if (fileWriteInt32(stream, proto->item.material) == -1) return -1;
if (fileWriteInt32(stream, proto->item.size) == -1) return -1;
if (_db_fwriteLong(stream, proto->item.weight) == -1) return -1;
if (fileWriteInt32(stream, proto->item.cost) == -1) return -1;
if (fileWriteInt32(stream, proto->item.inventoryFid) == -1) return -1;
if (fileWriteUInt8(stream, proto->item.field_80) == -1) return -1;
if (protoItemDataWrite(&(proto->item.data), proto->item.type, stream) == -1) return -1;
return 0;
case OBJ_TYPE_CRITTER:
if (fileWriteInt32(stream, proto->critter.lightDistance) == -1) return -1;
if (_db_fwriteLong(stream, proto->critter.lightIntensity) == -1) return -1;
if (fileWriteInt32(stream, proto->critter.flags) == -1) return -1;
if (fileWriteInt32(stream, proto->critter.extendedFlags) == -1) return -1;
if (fileWriteInt32(stream, proto->critter.sid) == -1) return -1;
if (fileWriteInt32(stream, proto->critter.headFid) == -1) return -1;
if (fileWriteInt32(stream, proto->critter.aiPacket) == -1) return -1;
if (fileWriteInt32(stream, proto->critter.team) == -1) return -1;
if (protoCritterDataWrite(stream, &(proto->critter.data)) == -1) return -1;
return 0;
case OBJ_TYPE_SCENERY:
if (fileWriteInt32(stream, proto->scenery.lightDistance) == -1) return -1;
if (_db_fwriteLong(stream, proto->scenery.lightIntensity) == -1) return -1;
if (fileWriteInt32(stream, proto->scenery.flags) == -1) return -1;
if (fileWriteInt32(stream, proto->scenery.extendedFlags) == -1) return -1;
if (fileWriteInt32(stream, proto->scenery.sid) == -1) return -1;
if (fileWriteInt32(stream, proto->scenery.type) == -1) return -1;
if (fileWriteInt32(stream, proto->scenery.field_2C) == -1) return -1;
if (fileWriteUInt8(stream, proto->scenery.field_34) == -1) return -1;
if (protoSceneryDataWrite(&(proto->scenery.data), proto->scenery.type, stream) == -1) return -1;
case OBJ_TYPE_WALL:
if (fileWriteInt32(stream, proto->wall.lightDistance) == -1) return -1;
if (_db_fwriteLong(stream, proto->wall.lightIntensity) == -1) return -1;
if (fileWriteInt32(stream, proto->wall.flags) == -1) return -1;
if (fileWriteInt32(stream, proto->wall.extendedFlags) == -1) return -1;
if (fileWriteInt32(stream, proto->wall.sid) == -1) return -1;
if (fileWriteInt32(stream, proto->wall.material) == -1) return -1;
return 0;
case OBJ_TYPE_TILE:
if (fileWriteInt32(stream, proto->tile.flags) == -1) return -1;
if (fileWriteInt32(stream, proto->tile.extendedFlags) == -1) return -1;
if (fileWriteInt32(stream, proto->tile.sid) == -1) return -1;
if (fileWriteInt32(stream, proto->tile.material) == -1) return -1;
return 0;
case OBJ_TYPE_MISC:
if (fileWriteInt32(stream, proto->misc.lightDistance) == -1) return -1;
if (_db_fwriteLong(stream, proto->misc.lightIntensity) == -1) return -1;
if (fileWriteInt32(stream, proto->misc.flags) == -1) return -1;
if (fileWriteInt32(stream, proto->misc.extendedFlags) == -1) return -1;
return 0;
}
return -1;
}
// 0x4A1B30
int _proto_save_pid(int pid)
{
Proto* proto;
if (protoGetProto(pid, &proto) == -1) {
return -1;
}
char path[260];
_proto_make_path(path, pid);
2022-05-19 01:51:26 -07:00
strcat(path, "\\");
_proto_list_str(pid, path + strlen(path));
File* stream = fileOpen(path, "wb");
if (stream == NULL) {
return -1;
}
int rc = protoWrite(proto, stream);
fileClose(stream);
return rc;
}
// 0x4A1C3C
2022-06-19 04:42:07 -07:00
static int _proto_load_pid(int pid, Proto** protoPtr)
2022-05-19 01:51:26 -07:00
{
2022-05-28 02:34:49 -07:00
char path[COMPAT_MAX_PATH];
_proto_make_path(path, pid);
2022-05-19 01:51:26 -07:00
strcat(path, "\\");
if (_proto_list_str(pid, path + strlen(path)) == -1) {
return -1;
}
File* stream = fileOpen(path, "rb");
if (stream == NULL) {
debugPrint("\nError: Can't fopen proto!\n");
*protoPtr = NULL;
return -1;
}
if (_proto_find_free_subnode(PID_TYPE(pid), protoPtr) == -1) {
2022-05-19 01:51:26 -07:00
fileClose(stream);
return -1;
}
if (protoRead(*protoPtr, stream) != 0) {
fileClose(stream);
return -1;
}
fileClose(stream);
return 0;
}
2023-04-18 23:21:38 -07:00
// 0x4A1D98
2022-06-19 04:42:07 -07:00
static int _proto_find_free_subnode(int type, Proto** protoPtr)
2022-05-19 01:51:26 -07:00
{
2023-04-18 23:21:38 -07:00
Proto* proto = (Proto*)internal_malloc(proto_size(type));
2022-05-19 01:51:26 -07:00
*protoPtr = proto;
if (proto == NULL) {
return -1;
}
ProtoList* protoList = &(_protoLists[type]);
ProtoListExtent* protoListExtent = protoList->tail;
if (protoList->head != NULL) {
if (protoListExtent->length == PROTO_LIST_EXTENT_SIZE) {
2022-05-21 08:22:03 -07:00
ProtoListExtent* newExtent = protoListExtent->next = (ProtoListExtent*)internal_malloc(sizeof(ProtoListExtent));
2022-05-19 01:51:26 -07:00
if (protoListExtent == NULL) {
internal_free(proto);
*protoPtr = NULL;
return -1;
}
newExtent->length = 0;
newExtent->next = NULL;
protoList->tail = newExtent;
protoList->length++;
protoListExtent = newExtent;
}
} else {
2022-05-21 08:22:03 -07:00
protoListExtent = (ProtoListExtent*)internal_malloc(sizeof(ProtoListExtent));
2022-05-19 01:51:26 -07:00
if (protoListExtent == NULL) {
internal_free(proto);
*protoPtr = NULL;
return -1;
}
protoListExtent->next = NULL;
protoListExtent->length = 0;
protoList->length = 1;
protoList->tail = protoListExtent;
protoList->head = protoListExtent;
}
protoListExtent->proto[protoListExtent->length] = proto;
protoListExtent->length++;
return 0;
}
// Evict top most proto cache block.
//
// 0x4A2040
2022-06-19 04:42:07 -07:00
static void _proto_remove_some_list(int type)
2022-05-19 01:51:26 -07:00
{
ProtoList* protoList = &(_protoLists[type]);
ProtoListExtent* protoListExtent = protoList->head;
if (protoListExtent != NULL) {
protoList->length--;
protoList->head = protoListExtent->next;
for (int index = 0; index < protoListExtent->length; index++) {
internal_free(protoListExtent->proto[index]);
}
internal_free(protoListExtent);
}
}
// Clear proto cache of given type.
//
// 0x4A2094
2022-06-19 04:42:07 -07:00
static void _proto_remove_list(int type)
2022-05-19 01:51:26 -07:00
{
ProtoList* protoList = &(_protoLists[type]);
ProtoListExtent* curr = protoList->head;
while (curr != NULL) {
ProtoListExtent* next = curr->next;
for (int index = 0; index < curr->length; index++) {
internal_free(curr->proto[index]);
}
internal_free(curr);
curr = next;
}
protoList->head = NULL;
protoList->tail = NULL;
protoList->length = 0;
}
// Clear all proto cache.
//
// 0x4A20F4
void _proto_remove_all()
{
for (int index = 0; index < 6; index++) {
_proto_remove_list(index);
}
}
// proto_ptr
// 0x4A2108
int protoGetProto(int pid, Proto** protoPtr)
{
*protoPtr = NULL;
if (pid == -1) {
return -1;
}
if (pid == 0x1000000) {
*protoPtr = (Proto*)&gDudeProto;
return 0;
}
ProtoList* protoList = &(_protoLists[PID_TYPE(pid)]);
2022-05-19 01:51:26 -07:00
ProtoListExtent* protoListExtent = protoList->head;
while (protoListExtent != NULL) {
for (int index = 0; index < protoListExtent->length; index++) {
Proto* proto = (Proto*)protoListExtent->proto[index];
if (pid == proto->pid) {
*protoPtr = proto;
return 0;
}
}
protoListExtent = protoListExtent->next;
}
if (protoList->head != NULL && protoList->tail != NULL) {
if (PROTO_LIST_EXTENT_SIZE * protoList->length - (PROTO_LIST_EXTENT_SIZE - protoList->tail->length) > PROTO_LIST_MAX_ENTRIES) {
_proto_remove_some_list(PID_TYPE(pid));
2022-05-19 01:51:26 -07:00
}
}
return _proto_load_pid(pid, protoPtr);
}
// 0x4A21DC
2022-06-19 04:42:07 -07:00
static int _proto_new_id(int a1)
2022-05-19 01:51:26 -07:00
{
int result = _protoLists[a1].max_entries_num;
_protoLists[a1].max_entries_num = result + 1;
return result;
}
// 0x4A2214
2022-06-19 04:42:07 -07:00
static int _proto_max_id(int a1)
2022-05-19 01:51:26 -07:00
{
return _protoLists[a1].max_entries_num;
}
// 0x4A22C0
int _ResetPlayer()
{
Proto* proto;
protoGetProto(gDude->pid, &proto);
pcStatsReset();
protoCritterDataResetStats(&(proto->critter.data));
2022-08-14 11:45:58 -07:00
// SFALL: Fix base EMP DR not being properly initialized.
proto->critter.data.baseStats[STAT_DAMAGE_RESISTANCE_EMP] = 100;
2022-05-19 01:51:26 -07:00
critterReset();
2022-06-10 14:32:57 -07:00
characterEditorReset();
2022-05-19 01:51:26 -07:00
protoCritterDataResetSkills(&(proto->critter.data));
skillsReset();
perksReset();
traitsReset();
critterUpdateDerivedStats(gDude);
return 0;
}
2022-09-23 05:43:44 -07:00
} // namespace fallout