mirror of
https://github.com/LostArtefacts/TRX.git
synced 2025-04-28 12:47:58 +03:00
reformat with .clang-format
This commit is contained in:
parent
28df4be348
commit
bc9246b1d4
13 changed files with 1263 additions and 1333 deletions
7
.clang-format
Normal file
7
.clang-format
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
BasedOnStyle: Webkit
|
||||
IndentPPDirectives: BeforeHash
|
||||
ColumnLimit: 80
|
||||
AllowShortFunctionsOnASingleLine: InlineOnly
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
AlignAfterOpenBracket: AlwaysBreak
|
3
format
Executable file
3
format
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
shopt -s globstar
|
||||
clang-format-10 **/*.{c,h} -i
|
|
@ -4,6 +4,7 @@
|
|||
#include "util.h"
|
||||
|
||||
// data
|
||||
// clang-format off
|
||||
#define cd_drive VAR_I_(0x0045A010, char, '.')
|
||||
#define DEMO VAR_I_(0x0045F1C0, uint32_t, 0)
|
||||
#define dword_45A1F0 VAR_U_(0x0045A1F0, uint32_t)
|
||||
|
@ -46,5 +47,6 @@
|
|||
#define OldHitPoints VAR_U_(0x0045A02C, int32_t)
|
||||
#define PhdWinWidth VAR_U_(0x006CADD4, int32_t)
|
||||
#define PhdWinHeight VAR_U_(0x0068F3A8, int32_t)
|
||||
// clang-format on
|
||||
|
||||
#endif
|
||||
|
|
236
src/func.c
236
src/func.c
|
@ -1,13 +1,14 @@
|
|||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
#include "data.h"
|
||||
#include "func.h"
|
||||
#include "data.h"
|
||||
#include "mod.h"
|
||||
#include "struct.h"
|
||||
#include <math.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
static int TR1MGetOverlayScale(int base) {
|
||||
static int TR1MGetOverlayScale(int base)
|
||||
{
|
||||
double result = PhdWinWidth;
|
||||
result *= base;
|
||||
result /= 800.0;
|
||||
|
@ -20,17 +21,18 @@ static int TR1MGetOverlayScale(int base) {
|
|||
return round(result);
|
||||
}
|
||||
|
||||
static void TR1MRenderBar(int percent, int air) {
|
||||
static void TR1MRenderBar(int percent, int air)
|
||||
{
|
||||
const int p1 = -100;
|
||||
const int p2 = -200;
|
||||
const int p3 = -300;
|
||||
const int p4 = -400;
|
||||
const int percent_max = 100;
|
||||
|
||||
#define COLOR_BAR_SIZE 5
|
||||
#define COLOR_BAR_SIZE 5
|
||||
const int color_bar[2][COLOR_BAR_SIZE] = {
|
||||
{8, 11, 8, 6, 24},
|
||||
{32, 41, 32, 19, 21},
|
||||
{ 8, 11, 8, 6, 24 },
|
||||
{ 32, 41, 32, 19, 21 },
|
||||
};
|
||||
|
||||
const int color_border_1 = 19;
|
||||
|
@ -85,34 +87,32 @@ static void TR1MRenderBar(int percent, int air) {
|
|||
int color_type = air ? 1 : 0;
|
||||
int color_index = i * COLOR_BAR_SIZE / height;
|
||||
Insert2DLine(
|
||||
left,
|
||||
top + i,
|
||||
right,
|
||||
top + i,
|
||||
p4,
|
||||
color_bar[color_type][color_index]
|
||||
);
|
||||
left, top + i, right, top + i, p4,
|
||||
color_bar[color_type][color_index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void __cdecl init_game_malloc() {
|
||||
void __cdecl init_game_malloc()
|
||||
{
|
||||
TRACE("");
|
||||
GameAllocMemPointer = GameMemoryPointer;
|
||||
GameAllocMemFree = GameMemorySize;
|
||||
GameAllocMemUsed = 0;
|
||||
}
|
||||
|
||||
void __cdecl game_free(int free_size) {
|
||||
void __cdecl game_free(int free_size)
|
||||
{
|
||||
TRACE("");
|
||||
GameAllocMemPointer -= free_size;
|
||||
GameAllocMemFree += free_size;
|
||||
GameAllocMemUsed -= free_size;
|
||||
}
|
||||
|
||||
void __cdecl DB_Log(char *a1, ...) {
|
||||
void __cdecl DB_Log(char* a1, ...)
|
||||
{
|
||||
va_list va;
|
||||
char buffer[256] = {0};
|
||||
char buffer[256] = { 0 };
|
||||
|
||||
va_start(va, a1);
|
||||
if (!dword_45A1F0) {
|
||||
|
@ -123,26 +123,28 @@ void __cdecl DB_Log(char *a1, ...) {
|
|||
}
|
||||
}
|
||||
|
||||
const char *GetFullPath(const char *filename) {
|
||||
const char* GetFullPath(const char* filename)
|
||||
{
|
||||
TRACE(filename);
|
||||
#if defined FEATURE_NOCD_DATA
|
||||
sprintf(newpath, ".\\%s", filename);
|
||||
#else
|
||||
if (DEMO)
|
||||
sprintf(newpath, "%c:\\tomb\\%s", cd_drive, filename);
|
||||
else
|
||||
sprintf(newpath, "%c:\\%s", cd_drive, filename);
|
||||
#endif
|
||||
#if defined FEATURE_NOCD_DATA
|
||||
sprintf(newpath, ".\\%s", filename);
|
||||
#else
|
||||
if (DEMO)
|
||||
sprintf(newpath, "%c:\\tomb\\%s", cd_drive, filename);
|
||||
else
|
||||
sprintf(newpath, "%c:\\%s", cd_drive, filename);
|
||||
#endif
|
||||
return newpath;
|
||||
}
|
||||
|
||||
int FindCdDrive() {
|
||||
int FindCdDrive()
|
||||
{
|
||||
TRACE("");
|
||||
FILE *fp;
|
||||
FILE* fp;
|
||||
char root[5] = "C:\\";
|
||||
char tmp_path[MAX_PATH];
|
||||
|
||||
for (cd_drive = 'C'; cd_drive <= 'Z'; cd_drive ++) {
|
||||
for (cd_drive = 'C'; cd_drive <= 'Z'; cd_drive++) {
|
||||
root[0] = cd_drive;
|
||||
if (GetDriveType(root) == DRIVE_CDROM) {
|
||||
sprintf(tmp_path, "%c:\\tomb\\data\\title.phd", cd_drive);
|
||||
|
@ -163,7 +165,8 @@ int FindCdDrive() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int LoadRooms(FILE *fp) {
|
||||
int LoadRooms(FILE* fp)
|
||||
{
|
||||
TRACE("");
|
||||
uint16_t count2;
|
||||
uint32_t count4;
|
||||
|
@ -174,20 +177,15 @@ int LoadRooms(FILE *fp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
RoomInfo = (ROOM_INFO *)game_malloc(
|
||||
sizeof(ROOM_INFO) * RoomCount, GBUF_RoomInfos
|
||||
);
|
||||
RoomInfo = game_malloc(sizeof(ROOM_INFO) * RoomCount, GBUF_RoomInfos);
|
||||
if (!RoomInfo) {
|
||||
strcpy(StringToShow, "LoadRoom(): Could not allocate memory for rooms");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (
|
||||
ROOM_INFO *current_room_info = RoomInfo;
|
||||
i < RoomCount;
|
||||
++i, ++current_room_info
|
||||
) {
|
||||
for (ROOM_INFO* current_room_info = RoomInfo; i < RoomCount;
|
||||
++i, ++current_room_info) {
|
||||
// Room position
|
||||
_fread(¤t_room_info->x, sizeof(uint32_t), 1, fp);
|
||||
current_room_info->y = 0;
|
||||
|
@ -199,9 +197,8 @@ int LoadRooms(FILE *fp) {
|
|||
|
||||
// Room mesh
|
||||
_fread(&count4, sizeof(uint32_t), 1, fp);
|
||||
current_room_info->data = (uint16_t *)game_malloc(
|
||||
sizeof(uint16_t) * count4, GBUF_RoomMesh
|
||||
);
|
||||
current_room_info->data =
|
||||
game_malloc(sizeof(uint16_t) * count4, GBUF_RoomMesh);
|
||||
_fread(current_room_info->data, sizeof(uint16_t), count4, fp);
|
||||
|
||||
// Doors
|
||||
|
@ -209,22 +206,19 @@ int LoadRooms(FILE *fp) {
|
|||
if (!count2) {
|
||||
current_room_info->doors = NULL;
|
||||
} else {
|
||||
current_room_info->doors = (DOOR_INFOS *)game_malloc(
|
||||
sizeof(uint16_t) + sizeof(DOOR_INFO) * count2, GBUF_RoomDoor
|
||||
);
|
||||
current_room_info->doors = game_malloc(
|
||||
sizeof(uint16_t) + sizeof(DOOR_INFO) * count2, GBUF_RoomDoor);
|
||||
current_room_info->doors->count = count2;
|
||||
_fread(
|
||||
¤t_room_info->doors->door, sizeof(DOOR_INFO), count2, fp
|
||||
);
|
||||
¤t_room_info->doors->door, sizeof(DOOR_INFO), count2, fp);
|
||||
}
|
||||
|
||||
// Room floor
|
||||
_fread(¤t_room_info->x_size, sizeof(uint16_t), 1, fp);
|
||||
_fread(¤t_room_info->y_size, sizeof(uint16_t), 1, fp);
|
||||
count4 = current_room_info->y_size * current_room_info->x_size;
|
||||
current_room_info->floor = (FLOOR_INFO *)game_malloc(
|
||||
sizeof(FLOOR_INFO) * count4, GBUF_RoomFloor
|
||||
);
|
||||
current_room_info->floor =
|
||||
game_malloc(sizeof(FLOOR_INFO) * count4, GBUF_RoomFloor);
|
||||
_fread(current_room_info->floor, sizeof(FLOOR_INFO), count4, fp);
|
||||
|
||||
// Room lights
|
||||
|
@ -233,16 +227,12 @@ int LoadRooms(FILE *fp) {
|
|||
if (!current_room_info->num_lights) {
|
||||
current_room_info->light = NULL;
|
||||
} else {
|
||||
current_room_info->light = (LIGHT_INFO *)game_malloc(
|
||||
current_room_info->light = game_malloc(
|
||||
sizeof(LIGHT_INFO) * current_room_info->num_lights,
|
||||
GBUF_RoomLights
|
||||
);
|
||||
GBUF_RoomLights);
|
||||
_fread(
|
||||
current_room_info->light,
|
||||
sizeof(LIGHT_INFO),
|
||||
current_room_info->num_lights,
|
||||
fp
|
||||
);
|
||||
current_room_info->light, sizeof(LIGHT_INFO),
|
||||
current_room_info->num_lights, fp);
|
||||
}
|
||||
|
||||
// Static mesh infos
|
||||
|
@ -250,16 +240,12 @@ int LoadRooms(FILE *fp) {
|
|||
if (!current_room_info->num_meshes) {
|
||||
current_room_info->mesh = NULL;
|
||||
} else {
|
||||
current_room_info->mesh = (MESH_INFO *)game_malloc(
|
||||
current_room_info->mesh = game_malloc(
|
||||
sizeof(MESH_INFO) * current_room_info->num_meshes,
|
||||
GBUF_RoomStaticMeshInfos
|
||||
);
|
||||
GBUF_RoomStaticMeshInfos);
|
||||
_fread(
|
||||
current_room_info->mesh,
|
||||
sizeof(MESH_INFO),
|
||||
current_room_info->num_meshes,
|
||||
fp
|
||||
);
|
||||
current_room_info->mesh, sizeof(MESH_INFO),
|
||||
current_room_info->num_meshes, fp);
|
||||
}
|
||||
|
||||
// Flipped (alternative) room
|
||||
|
@ -285,17 +271,17 @@ int LoadRooms(FILE *fp) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
void __cdecl LevelStats(int level_id) {
|
||||
void __cdecl LevelStats(int level_id)
|
||||
{
|
||||
TRACE("");
|
||||
|
||||
if (TR1MConfig.disable_healing_between_levels) {
|
||||
TR1MData.stored_lara_health = LaraItem
|
||||
? LaraItem->hit_points
|
||||
: LARA_HITPOINTS;
|
||||
TR1MData.stored_lara_health =
|
||||
LaraItem ? LaraItem->hit_points : LARA_HITPOINTS;
|
||||
}
|
||||
|
||||
static char string[100];
|
||||
TEXTSTRING *txt;
|
||||
TEXTSTRING* txt;
|
||||
|
||||
TempVideoAdjust(HiRes, 1.0);
|
||||
T_InitPrint();
|
||||
|
@ -313,24 +299,14 @@ void __cdecl LevelStats(int level_id) {
|
|||
seconds %= 60;
|
||||
if (hours) {
|
||||
sprintf(
|
||||
string,
|
||||
"%s %d:%d%d:%d%d",
|
||||
string, "%s %d:%d%d:%d%d",
|
||||
"TIME TAKEN", // TODO: translation
|
||||
hours,
|
||||
minutes / 10,
|
||||
minutes % 10,
|
||||
seconds / 10,
|
||||
seconds % 10
|
||||
);
|
||||
hours, minutes / 10, minutes % 10, seconds / 10, seconds % 10);
|
||||
} else {
|
||||
sprintf(
|
||||
string,
|
||||
"%s %d:%d%d",
|
||||
string, "%s %d:%d%d",
|
||||
"TIME TAKEN", // TODO: translation
|
||||
minutes,
|
||||
seconds / 10,
|
||||
seconds % 10
|
||||
);
|
||||
minutes, seconds / 10, seconds % 10);
|
||||
}
|
||||
txt = T_Print(0, 70, 0, string);
|
||||
T_CentreH(txt, 1);
|
||||
|
@ -345,11 +321,9 @@ void __cdecl LevelStats(int level_id) {
|
|||
}
|
||||
SaveGame[0].secrets >>= 1;
|
||||
--secrets_total;
|
||||
}
|
||||
while (secrets_total);
|
||||
} while (secrets_total);
|
||||
sprintf(
|
||||
string,
|
||||
"%s %d %s %d",
|
||||
string, "%s %d %s %d",
|
||||
"SECRETS", // TODO: translation
|
||||
secrets_taken,
|
||||
"OF", // TODO: translation
|
||||
|
@ -360,7 +334,9 @@ void __cdecl LevelStats(int level_id) {
|
|||
T_CentreV(txt, 1);
|
||||
|
||||
// pickups
|
||||
sprintf(string, "%s %d", "PICKUPS", SaveGame[0].pickups); // TODO: translation
|
||||
sprintf(
|
||||
string, "%s %d", "PICKUPS",
|
||||
SaveGame[0].pickups); // TODO: translation
|
||||
txt = T_Print(0, 10, 0, string);
|
||||
T_CentreH(txt, 1);
|
||||
T_CentreV(txt, 1);
|
||||
|
@ -425,7 +401,8 @@ void __cdecl LevelStats(int level_id) {
|
|||
TempVideoRemove();
|
||||
}
|
||||
|
||||
int __cdecl S_LoadLevel(int level_id) {
|
||||
int __cdecl S_LoadLevel(int level_id)
|
||||
{
|
||||
TRACE("%d", level_id);
|
||||
int ret = LoadLevel(LevelNames[level_id], level_id);
|
||||
|
||||
|
@ -447,15 +424,18 @@ int __cdecl S_LoadLevel(int level_id) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
void __cdecl S_DrawHealthBar(int32_t percent) {
|
||||
void __cdecl S_DrawHealthBar(int32_t percent)
|
||||
{
|
||||
TR1MRenderBar(percent, 0);
|
||||
}
|
||||
|
||||
void __cdecl S_DrawAirBar(int32_t percent) {
|
||||
void __cdecl S_DrawAirBar(int32_t percent)
|
||||
{
|
||||
TR1MRenderBar(percent, 1);
|
||||
}
|
||||
|
||||
int __cdecl LoadItems(FILE *handle) {
|
||||
int __cdecl LoadItems(FILE* handle)
|
||||
{
|
||||
int32_t item_count = 0;
|
||||
_fread(&item_count, sizeof(int32_t), 1u, handle);
|
||||
|
||||
|
@ -471,8 +451,7 @@ int __cdecl LoadItems(FILE *handle) {
|
|||
if (!Items) {
|
||||
strcpy(
|
||||
StringToShow,
|
||||
"LoadItems(): Unable to allocate memory for 'items'"
|
||||
);
|
||||
"LoadItems(): Unable to allocate memory for 'items'");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -480,7 +459,7 @@ int __cdecl LoadItems(FILE *handle) {
|
|||
InitialiseItemArray(NUMBER_ITEMS);
|
||||
|
||||
for (int i = 0; i < item_count; ++i) {
|
||||
ITEM_INFO *item = &Items[i];
|
||||
ITEM_INFO* item = &Items[i];
|
||||
_fread(&item->object_number, 2u, 1u, handle);
|
||||
_fread(&item->room_number, 2u, 1u, handle);
|
||||
_fread(&item->pos.x, 4u, 1u, handle);
|
||||
|
@ -491,21 +470,17 @@ int __cdecl LoadItems(FILE *handle) {
|
|||
_fread(&item->flags, 2u, 1u, handle);
|
||||
|
||||
if (item->object_number < 0
|
||||
|| item->object_number >= ID_NUMBER_OBJECTS
|
||||
) {
|
||||
|| item->object_number >= ID_NUMBER_OBJECTS) {
|
||||
sprintf(
|
||||
StringToShow,
|
||||
"LoadItems(): Bad Object number (%d) on Item %d",
|
||||
item->object_number,
|
||||
i
|
||||
);
|
||||
item->object_number, i);
|
||||
S_ExitSystem(StringToShow);
|
||||
}
|
||||
|
||||
if (TR1MConfig.disable_medpacks && (
|
||||
item->object_number == ID_LARGE_MEDIPACK_ITEM ||
|
||||
item->object_number == ID_SMALL_MEDIPACK_ITEM
|
||||
)) {
|
||||
if (TR1MConfig.disable_medpacks
|
||||
&& (item->object_number == ID_LARGE_MEDIPACK_ITEM
|
||||
|| item->object_number == ID_SMALL_MEDIPACK_ITEM)) {
|
||||
item->pos.x = -1;
|
||||
item->pos.y = -1;
|
||||
item->pos.z = -1;
|
||||
|
@ -519,7 +494,8 @@ int __cdecl LoadItems(FILE *handle) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
void __cdecl InitialiseLara() {
|
||||
void __cdecl InitialiseLara()
|
||||
{
|
||||
TRACE("");
|
||||
LaraItem->collidable = 0;
|
||||
LaraItem->data = &Lara;
|
||||
|
@ -574,33 +550,34 @@ void __cdecl InitialiseLara() {
|
|||
InitialiseLaraInventory(CurrentLevel);
|
||||
}
|
||||
|
||||
void __cdecl InitialiseFXArray() {
|
||||
void __cdecl InitialiseFXArray()
|
||||
{
|
||||
TRACE("");
|
||||
NextFxActive = NO_ITEM;
|
||||
NextFxFree = 0;
|
||||
FX_INFO *fx = Effects;
|
||||
FX_INFO* fx = Effects;
|
||||
for (int i = 1; i < NUM_EFFECTS; i++, fx++) {
|
||||
fx->next_fx = i;
|
||||
}
|
||||
fx->next_fx = NO_ITEM;
|
||||
}
|
||||
|
||||
void __cdecl InitialiseLOTArray() {
|
||||
void __cdecl InitialiseLOTArray()
|
||||
{
|
||||
TRACE("");
|
||||
BaddieSlots = game_malloc(
|
||||
NUM_SLOTS * sizeof(CREATURE_INFO), GBUF_CreatureData
|
||||
);
|
||||
CREATURE_INFO *creature = BaddieSlots;
|
||||
BaddieSlots =
|
||||
game_malloc(NUM_SLOTS * sizeof(CREATURE_INFO), GBUF_CreatureData);
|
||||
CREATURE_INFO* creature = BaddieSlots;
|
||||
for (int i = 0; i < NUM_SLOTS; i++, creature++) {
|
||||
creature->item_num = NO_ITEM;
|
||||
creature->LOT.node = game_malloc(
|
||||
sizeof(BOX_NODE) * NumberBoxes, GBUF_CreatureLot
|
||||
);
|
||||
creature->LOT.node =
|
||||
game_malloc(sizeof(BOX_NODE) * NumberBoxes, GBUF_CreatureLot);
|
||||
}
|
||||
SlotsUsed = 0;
|
||||
}
|
||||
|
||||
void __cdecl DrawHealthBar() {
|
||||
void __cdecl DrawHealthBar()
|
||||
{
|
||||
int hit_points = LaraItem->hit_points;
|
||||
if (hit_points < 0) {
|
||||
hit_points = 0;
|
||||
|
@ -622,8 +599,10 @@ void __cdecl DrawHealthBar() {
|
|||
}
|
||||
}
|
||||
|
||||
void __cdecl DrawAirBar() {
|
||||
if (Lara.water_status != LARA_UNDERWATER && Lara.water_status != LARA_SURFACE) {
|
||||
void __cdecl DrawAirBar()
|
||||
{
|
||||
if (Lara.water_status != LARA_UNDERWATER
|
||||
&& Lara.water_status != LARA_SURFACE) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -637,7 +616,8 @@ void __cdecl DrawAirBar() {
|
|||
S_DrawAirBar(air * 100 / LARA_AIR);
|
||||
}
|
||||
|
||||
void __cdecl DrawPickups() {
|
||||
void __cdecl DrawPickups()
|
||||
{
|
||||
int old_game_timer = OldGameTimer;
|
||||
OldGameTimer = SaveGame[0].timer;
|
||||
int16_t time = SaveGame[0].timer - old_game_timer;
|
||||
|
@ -647,21 +627,21 @@ void __cdecl DrawPickups() {
|
|||
int x = PhdWinWidth - PhdWinWidth / 10;
|
||||
int sprite_width = 4 * (PhdWinWidth / 10) / 3;
|
||||
for (int i = 0; i < NUM_PU; i++) {
|
||||
DISPLAYPU *pu = &Pickups[i];
|
||||
DISPLAYPU* pu = &Pickups[i];
|
||||
pu->duration -= time;
|
||||
if (pu->duration <= 0) {
|
||||
pu->duration = 0;
|
||||
} else {
|
||||
S_DrawScreenSprite2d(
|
||||
x, y, TR1MGetOverlayScale(12288), pu->sprnum, 4096
|
||||
);
|
||||
x, y, TR1MGetOverlayScale(12288), pu->sprnum, 4096);
|
||||
x -= sprite_width;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void __cdecl DrawGameInfo() {
|
||||
void __cdecl DrawGameInfo()
|
||||
{
|
||||
DrawAmmoInfo();
|
||||
if (OverlayStatus > 0) {
|
||||
DrawHealthBar();
|
||||
|
|
14
src/func.h
14
src/func.h
|
@ -1,9 +1,10 @@
|
|||
#ifndef TR1MAIN_FUNC_H
|
||||
#define TR1MAIN_FUNC_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "util.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// clang-format off
|
||||
#define game_malloc ((void __cdecl*(*)(uint32_t length, int type))0x0041E2F0)
|
||||
#define ins_line ((int __cdecl(*)(int, int, int, int, int, char))0x00402710)
|
||||
#define _fread ((size_t __cdecl(*)(void *, size_t, size_t, FILE *))0x00442C20)
|
||||
|
@ -24,7 +25,7 @@
|
|||
#define ModifyStartInfo ((void __cdecl(*)(int level_id))0x00434520)
|
||||
#define TempVideoRemove ((void __cdecl(*)())0x004167D0)
|
||||
#define T_InitPrint ((void __cdecl(*)())0x00439750)
|
||||
#define T_Print ((TEXTSTRING *__cdecl(*)(int16_t xpos, int16_t ypos, int16_t zpos, const char *string))0x00439780)
|
||||
#define T_Print ((TEXTSTRING* __cdecl(*)(int16_t xpos, int16_t ypos, int16_t zpos, const char *string))0x00439780)
|
||||
#define T_CentreH ((void __cdecl(*)(TEXTSTRING *text_string, int16_t enable))0x004399A0)
|
||||
#define T_CentreV ((void __cdecl(*)(TEXTSTRING *text_string, int16_t enable))0x004399C0)
|
||||
#define TempVideoAdjust ((void __cdecl(*)(int hires, double sizer))0x00416550)
|
||||
|
@ -32,18 +33,19 @@
|
|||
#define DrawAmmoInfo ((void __cdecl(*)())0x0041DF50)
|
||||
#define S_DrawScreenSprite2d ((void __cdecl(*)(int32_t x, int32_t y, int32_t scale, int16_t sprnum, int16_t brightness))0x00435D80)
|
||||
#define Insert2DLine ((void __cdecl(*)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t z, uint8_t color))0x00402710)
|
||||
// clang-format on
|
||||
|
||||
void __cdecl init_game_malloc();
|
||||
void __cdecl game_free(int free_size);
|
||||
void __cdecl DB_Log(char *a1, ...);
|
||||
const char* __cdecl GetFullPath(const char *filename);
|
||||
void __cdecl DB_Log(char* a1, ...);
|
||||
const char* __cdecl GetFullPath(const char* filename);
|
||||
int __cdecl FindCdDrive();
|
||||
int __cdecl LoadRooms(FILE *fp);
|
||||
int __cdecl LoadRooms(FILE* fp);
|
||||
void __cdecl LevelStats(int level_id);
|
||||
int __cdecl S_LoadLevel(int level_id);
|
||||
void __cdecl S_DrawHealthBar(int percent);
|
||||
void __cdecl S_DrawAirBar(int percent);
|
||||
int __cdecl LoadItems(FILE *handle);
|
||||
int __cdecl LoadItems(FILE* handle);
|
||||
void __cdecl InitialiseLara();
|
||||
void __cdecl InitialiseFXArray();
|
||||
void __cdecl InitialiseLOTArray();
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -32,252 +32,218 @@
|
|||
#define _JSON_H
|
||||
|
||||
#ifndef json_char
|
||||
#define json_char char
|
||||
#define json_char char
|
||||
#endif
|
||||
|
||||
#ifndef json_int_t
|
||||
#ifndef _MSC_VER
|
||||
#include <inttypes.h>
|
||||
#define json_int_t int64_t
|
||||
#else
|
||||
#define json_int_t __int64
|
||||
#endif
|
||||
#ifndef _MSC_VER
|
||||
#include <inttypes.h>
|
||||
#define json_int_t int64_t
|
||||
#else
|
||||
#define json_int_t __int64
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <string.h>
|
||||
#include <string.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned long max_memory;
|
||||
int settings;
|
||||
typedef struct {
|
||||
unsigned long max_memory;
|
||||
int settings;
|
||||
|
||||
/* Custom allocator support (leave null to use malloc/free)
|
||||
*/
|
||||
/* Custom allocator support (leave null to use malloc/free)
|
||||
*/
|
||||
|
||||
void * (* mem_alloc) (size_t, int zero, void * user_data);
|
||||
void (* mem_free) (void *, void * user_data);
|
||||
void* (*mem_alloc)(size_t, int zero, void* user_data);
|
||||
void (*mem_free)(void*, void* user_data);
|
||||
|
||||
void * user_data; /* will be passed to mem_alloc and mem_free */
|
||||
void* user_data; /* will be passed to mem_alloc and mem_free */
|
||||
|
||||
size_t value_extra; /* how much extra space to allocate for values? */
|
||||
size_t value_extra; /* how much extra space to allocate for values? */
|
||||
|
||||
} json_settings;
|
||||
|
||||
#define json_enable_comments 0x01
|
||||
#define json_enable_comments 0x01
|
||||
|
||||
typedef enum
|
||||
{
|
||||
json_none,
|
||||
json_object,
|
||||
json_array,
|
||||
json_integer,
|
||||
json_double,
|
||||
json_string,
|
||||
json_boolean,
|
||||
json_null
|
||||
typedef enum {
|
||||
json_none,
|
||||
json_object,
|
||||
json_array,
|
||||
json_integer,
|
||||
json_double,
|
||||
json_string,
|
||||
json_boolean,
|
||||
json_null
|
||||
|
||||
} json_type;
|
||||
|
||||
extern const struct _json_value json_value_none;
|
||||
|
||||
typedef struct _json_object_entry
|
||||
{
|
||||
json_char * name;
|
||||
|
||||
typedef struct _json_object_entry {
|
||||
json_char* name;
|
||||
unsigned int name_length;
|
||||
|
||||
struct _json_value * value;
|
||||
|
||||
|
||||
struct _json_value* value;
|
||||
|
||||
} json_object_entry;
|
||||
|
||||
typedef struct _json_value
|
||||
{
|
||||
struct _json_value * parent;
|
||||
typedef struct _json_value {
|
||||
struct _json_value* parent;
|
||||
|
||||
json_type type;
|
||||
json_type type;
|
||||
|
||||
union
|
||||
{
|
||||
int boolean;
|
||||
json_int_t integer;
|
||||
double dbl;
|
||||
union {
|
||||
int boolean;
|
||||
json_int_t integer;
|
||||
double dbl;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned int length;
|
||||
json_char * ptr; /* null terminated */
|
||||
struct {
|
||||
unsigned int length;
|
||||
json_char* ptr; /* null terminated */
|
||||
|
||||
} string;
|
||||
} string;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned int length;
|
||||
struct {
|
||||
unsigned int length;
|
||||
|
||||
json_object_entry * values;
|
||||
json_object_entry* values;
|
||||
|
||||
#if defined(__cplusplus) && __cplusplus >= 201103L
|
||||
decltype(values) begin () const
|
||||
{ return values;
|
||||
}
|
||||
decltype(values) end () const
|
||||
{ return values + length;
|
||||
}
|
||||
#endif
|
||||
#if defined(__cplusplus) && __cplusplus >= 201103L
|
||||
decltype(values) begin() const { return values; }
|
||||
decltype(values) end() const { return values + length; }
|
||||
#endif
|
||||
|
||||
} object;
|
||||
} object;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned int length;
|
||||
struct _json_value ** values;
|
||||
struct {
|
||||
unsigned int length;
|
||||
struct _json_value** values;
|
||||
|
||||
#if defined(__cplusplus) && __cplusplus >= 201103L
|
||||
decltype(values) begin () const
|
||||
{ return values;
|
||||
}
|
||||
decltype(values) end () const
|
||||
{ return values + length;
|
||||
}
|
||||
#endif
|
||||
#if defined(__cplusplus) && __cplusplus >= 201103L
|
||||
decltype(values) begin() const { return values; }
|
||||
decltype(values) end() const { return values + length; }
|
||||
#endif
|
||||
|
||||
} array;
|
||||
} array;
|
||||
|
||||
} u;
|
||||
} u;
|
||||
|
||||
union
|
||||
{
|
||||
struct _json_value * next_alloc;
|
||||
void * object_mem;
|
||||
union {
|
||||
struct _json_value* next_alloc;
|
||||
void* object_mem;
|
||||
|
||||
} _reserved;
|
||||
} _reserved;
|
||||
|
||||
#ifdef JSON_TRACK_SOURCE
|
||||
#ifdef JSON_TRACK_SOURCE
|
||||
|
||||
/* Location of the value in the source JSON
|
||||
*/
|
||||
unsigned int line, col;
|
||||
/* Location of the value in the source JSON
|
||||
*/
|
||||
unsigned int line, col;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Some C++ operator sugar */
|
||||
|
||||
/* Some C++ operator sugar */
|
||||
#ifdef __cplusplus
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
public:
|
||||
|
||||
inline _json_value ()
|
||||
{ memset (this, 0, sizeof (_json_value));
|
||||
}
|
||||
|
||||
inline const struct _json_value &operator [] (int index) const
|
||||
{
|
||||
if (type != json_array || index < 0
|
||||
|| ((unsigned int) index) >= u.array.length)
|
||||
{
|
||||
return json_value_none;
|
||||
}
|
||||
|
||||
return *u.array.values [index];
|
||||
}
|
||||
|
||||
inline const struct _json_value &operator [] (const char * index) const
|
||||
{
|
||||
if (type != json_object)
|
||||
return json_value_none;
|
||||
|
||||
for (unsigned int i = 0; i < u.object.length; ++ i)
|
||||
if (!strcmp (u.object.values [i].name, index))
|
||||
return *u.object.values [i].value;
|
||||
public:
|
||||
inline _json_value() { memset(this, 0, sizeof(_json_value)); }
|
||||
|
||||
inline const struct _json_value& operator[](int index) const
|
||||
{
|
||||
if (type != json_array || index < 0
|
||||
|| ((unsigned int)index) >= u.array.length) {
|
||||
return json_value_none;
|
||||
}
|
||||
}
|
||||
|
||||
inline operator const char * () const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case json_string:
|
||||
return u.string.ptr;
|
||||
return *u.array.values[index];
|
||||
}
|
||||
|
||||
default:
|
||||
return "";
|
||||
};
|
||||
}
|
||||
inline const struct _json_value& operator[](const char* index) const
|
||||
{
|
||||
if (type != json_object)
|
||||
return json_value_none;
|
||||
|
||||
inline operator json_int_t () const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case json_integer:
|
||||
return u.integer;
|
||||
for (unsigned int i = 0; i < u.object.length; ++i)
|
||||
if (!strcmp(u.object.values[i].name, index))
|
||||
return *u.object.values[i].value;
|
||||
|
||||
case json_double:
|
||||
return (json_int_t) u.dbl;
|
||||
return json_value_none;
|
||||
}
|
||||
|
||||
default:
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
inline operator const char*() const
|
||||
{
|
||||
switch (type) {
|
||||
case json_string:
|
||||
return u.string.ptr;
|
||||
|
||||
inline operator bool () const
|
||||
{
|
||||
if (type != json_boolean)
|
||||
return false;
|
||||
default:
|
||||
return "";
|
||||
};
|
||||
}
|
||||
|
||||
return u.boolean != 0;
|
||||
}
|
||||
inline operator json_int_t() const
|
||||
{
|
||||
switch (type) {
|
||||
case json_integer:
|
||||
return u.integer;
|
||||
|
||||
inline operator double () const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case json_integer:
|
||||
return (double) u.integer;
|
||||
case json_double:
|
||||
return (json_int_t)u.dbl;
|
||||
|
||||
case json_double:
|
||||
return u.dbl;
|
||||
default:
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
default:
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
inline operator bool() const
|
||||
{
|
||||
if (type != json_boolean)
|
||||
return false;
|
||||
|
||||
#endif
|
||||
return u.boolean != 0;
|
||||
}
|
||||
|
||||
inline operator double() const
|
||||
{
|
||||
switch (type) {
|
||||
case json_integer:
|
||||
return (double)u.integer;
|
||||
|
||||
case json_double:
|
||||
return u.dbl;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} json_value;
|
||||
|
||||
json_value * json_parse (const json_char * json,
|
||||
size_t length);
|
||||
|
||||
json_value* json_parse(const json_char* json, size_t length);
|
||||
|
||||
#define json_error_max 128
|
||||
json_value * json_parse_ex (json_settings * settings,
|
||||
const json_char * json,
|
||||
size_t length,
|
||||
char * error);
|
||||
|
||||
void json_value_free (json_value *);
|
||||
json_value* json_parse_ex(
|
||||
json_settings* settings, const json_char* json, size_t length, char* error);
|
||||
|
||||
void json_value_free(json_value*);
|
||||
|
||||
/* Not usually necessary, unless you used a custom mem_alloc and now want to
|
||||
* use a custom mem_free.
|
||||
*/
|
||||
void json_value_free_ex (json_settings * settings,
|
||||
json_value *);
|
||||
|
||||
void json_value_free_ex(json_settings* settings, json_value*);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -1,24 +1,20 @@
|
|||
#include <string.h>
|
||||
#include "json_utils.h"
|
||||
#include <string.h>
|
||||
|
||||
json_value *tr1m_json_get_field(
|
||||
json_value *root,
|
||||
json_type field_type,
|
||||
const char *name,
|
||||
int *pIndex
|
||||
) {
|
||||
json_value* tr1m_json_get_field(
|
||||
json_value* root, json_type field_type, const char* name, int* pIndex)
|
||||
{
|
||||
if (root == NULL || root->type != json_object) {
|
||||
return NULL;
|
||||
}
|
||||
json_value *result = NULL;
|
||||
json_value* result = NULL;
|
||||
unsigned int len = name ? strlen(name) : 0;
|
||||
unsigned int i = pIndex ? *pIndex : 0;
|
||||
for (; i < root->u.object.length; ++i) {
|
||||
if (root->u.object.values[i].value->type == field_type) {
|
||||
if (!name || (
|
||||
len == root->u.object.values[i].name_length
|
||||
&& !strncmp(root->u.object.values[i].name, name, len)
|
||||
)) {
|
||||
if (!name
|
||||
|| (len == root->u.object.values[i].name_length
|
||||
&& !strncmp(root->u.object.values[i].name, name, len))) {
|
||||
result = root->u.object.values[i].value;
|
||||
break;
|
||||
}
|
||||
|
@ -30,7 +26,8 @@ json_value *tr1m_json_get_field(
|
|||
return result;
|
||||
}
|
||||
|
||||
int tr1m_json_get_boolean_value(json_value *root, const char *name) {
|
||||
json_value *field = tr1m_json_get_field(root, json_boolean, name, NULL);
|
||||
int tr1m_json_get_boolean_value(json_value* root, const char* name)
|
||||
{
|
||||
json_value* field = tr1m_json_get_field(root, json_boolean, name, NULL);
|
||||
return field ? field->u.boolean : 0;
|
||||
}
|
||||
|
|
|
@ -3,13 +3,9 @@
|
|||
|
||||
#include "json-parser/json.h"
|
||||
|
||||
json_value *tr1m_json_get_field(
|
||||
json_value *root,
|
||||
json_type field_type,
|
||||
const char *name,
|
||||
int *pIndex
|
||||
);
|
||||
json_value* tr1m_json_get_field(
|
||||
json_value* root, json_type field_type, const char* name, int* pIndex);
|
||||
|
||||
int tr1m_json_get_boolean_value(json_value *root, const char *name);
|
||||
int tr1m_json_get_boolean_value(json_value* root, const char* name);
|
||||
|
||||
#endif
|
||||
|
|
66
src/main.c
Executable file → Normal file
66
src/main.c
Executable file → Normal file
|
@ -1,15 +1,16 @@
|
|||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include "func.h"
|
||||
#include "json_utils.h"
|
||||
#include "mod.h"
|
||||
#include "struct.h"
|
||||
#include "util.h"
|
||||
#include "func.h"
|
||||
#include "mod.h"
|
||||
|
||||
HINSTANCE hInstance = NULL;
|
||||
|
||||
static void tr1m_inject() {
|
||||
static void tr1m_inject()
|
||||
{
|
||||
INJECT(0x0041AF90, S_LoadLevel);
|
||||
INJECT(0x0041B3F0, LoadRooms);
|
||||
INJECT(0x0041BC60, LoadItems);
|
||||
|
@ -27,8 +28,9 @@ static void tr1m_inject() {
|
|||
INJECT(0x00430450, S_DrawAirBar);
|
||||
}
|
||||
|
||||
static int tr1m_read_config() {
|
||||
FILE *fp = fopen("TR1Main.json", "rb");
|
||||
static int tr1m_read_config()
|
||||
{
|
||||
FILE* fp = fopen("TR1Main.json", "rb");
|
||||
if (!fp) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -37,7 +39,7 @@ static int tr1m_read_config() {
|
|||
int cfg_size = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
|
||||
char *cfg_data = malloc(cfg_size);
|
||||
char* cfg_data = malloc(cfg_size);
|
||||
if (!cfg_data) {
|
||||
fclose(fp);
|
||||
return 0;
|
||||
|
@ -45,44 +47,40 @@ static int tr1m_read_config() {
|
|||
fread(cfg_data, 1, cfg_size, fp);
|
||||
fclose(fp);
|
||||
|
||||
json_value *json = json_parse((const json_char*)cfg_data, cfg_size);
|
||||
json_value* json = json_parse((const json_char*)cfg_data, cfg_size);
|
||||
|
||||
TR1MConfig.disable_healing_between_levels = tr1m_json_get_boolean_value(
|
||||
json, "disable_healing_between_levels"
|
||||
);
|
||||
TR1MConfig.disable_medpacks = tr1m_json_get_boolean_value(
|
||||
json, "disable_medpacks"
|
||||
);
|
||||
TR1MConfig.fix_end_of_level_freeze = tr1m_json_get_boolean_value(
|
||||
json, "fix_end_of_level_freeze"
|
||||
);
|
||||
TR1MConfig.disable_healing_between_levels =
|
||||
tr1m_json_get_boolean_value(json, "disable_healing_between_levels");
|
||||
TR1MConfig.disable_medpacks =
|
||||
tr1m_json_get_boolean_value(json, "disable_medpacks");
|
||||
TR1MConfig.fix_end_of_level_freeze =
|
||||
tr1m_json_get_boolean_value(json, "fix_end_of_level_freeze");
|
||||
|
||||
json_value_free(json);
|
||||
free(cfg_data);
|
||||
return 1;
|
||||
}
|
||||
|
||||
BOOL APIENTRY DllMain(
|
||||
HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved
|
||||
) {
|
||||
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
||||
{
|
||||
switch (fdwReason) {
|
||||
case DLL_PROCESS_ATTACH:
|
||||
freopen("./TR1Main.log", "w", stdout);
|
||||
tr1m_read_config();
|
||||
TRACE("Attached");
|
||||
hInstance = hinstDLL;
|
||||
tr1m_inject();
|
||||
break;
|
||||
case DLL_PROCESS_ATTACH:
|
||||
freopen("./TR1Main.log", "w", stdout);
|
||||
tr1m_read_config();
|
||||
TRACE("Attached");
|
||||
hInstance = hinstDLL;
|
||||
tr1m_inject();
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
TRACE("Detached");
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
TRACE("Detached");
|
||||
break;
|
||||
|
||||
case DLL_THREAD_ATTACH:
|
||||
break;
|
||||
case DLL_THREAD_ATTACH:
|
||||
break;
|
||||
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
|
306
src/struct.h
306
src/struct.h
|
@ -1,30 +1,30 @@
|
|||
#ifndef TR1MAIN_STRUCT_H
|
||||
#define TR1MAIN_STRUCT_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef uint16_t PHD_ANGLE;
|
||||
typedef uint32_t SG_COL;
|
||||
typedef void UNKNOWN_STRUCT;
|
||||
|
||||
#define NUM_PU 3
|
||||
#define NUM_SLOTS 8
|
||||
#define MAX_ROOMS 1024
|
||||
#define NUMBER_ITEMS 256
|
||||
#define MAX_SECRETS 16
|
||||
#define MAX_SAVEGAME_BUFFER (10*1024)
|
||||
#define SAVEGAME_VERSION 0x1
|
||||
#define LARA_HITPOINTS 1000
|
||||
#define LARA_AIR 1800
|
||||
#define NO_ITEM -1
|
||||
#define NUM_PU 3
|
||||
#define NUM_SLOTS 8
|
||||
#define MAX_ROOMS 1024
|
||||
#define NUMBER_ITEMS 256
|
||||
#define MAX_SECRETS 16
|
||||
#define MAX_SAVEGAME_BUFFER (10 * 1024)
|
||||
#define SAVEGAME_VERSION 0x1
|
||||
#define LARA_HITPOINTS 1000
|
||||
#define LARA_AIR 1800
|
||||
#define NO_ITEM -1
|
||||
|
||||
#define NUM_EFFECTS 100
|
||||
|
||||
#define TREAD_A 108
|
||||
#define TREAD_F 1736
|
||||
#define STOP_A 11
|
||||
#define STOP_F 185
|
||||
#define STOP_A 11
|
||||
#define STOP_F 185
|
||||
|
||||
#define WALL_L 1024
|
||||
#define STEP_L 256
|
||||
|
@ -39,119 +39,119 @@ typedef enum {
|
|||
typedef enum {
|
||||
LARA_ABOVEWATER = 0,
|
||||
LARA_UNDERWATER = 1,
|
||||
LARA_SURFACE = 2,
|
||||
LARA_SURFACE = 2,
|
||||
} LARA_WATER_STATES;
|
||||
|
||||
typedef enum {
|
||||
AS_WALK = 0,
|
||||
AS_RUN = 1,
|
||||
AS_STOP = 2,
|
||||
AS_FORWARDJUMP = 3,
|
||||
AS_POSE = 4,
|
||||
AS_FASTBACK = 5,
|
||||
AS_TURN_R = 6,
|
||||
AS_TURN_L = 7,
|
||||
AS_DEATH = 8,
|
||||
AS_FASTFALL = 9,
|
||||
AS_HANG = 10,
|
||||
AS_REACH = 11,
|
||||
AS_SPLAT = 12,
|
||||
AS_TREAD = 13,
|
||||
AS_LAND = 14,
|
||||
AS_COMPRESS = 15,
|
||||
AS_BACK = 16,
|
||||
AS_SWIM = 17,
|
||||
AS_GLIDE = 18,
|
||||
AS_NULL = 19,
|
||||
AS_FASTTURN = 20,
|
||||
AS_STEPRIGHT = 21,
|
||||
AS_STEPLEFT = 22,
|
||||
AS_HIT = 23,
|
||||
AS_SLIDE = 24,
|
||||
AS_BACKJUMP = 25,
|
||||
AS_RIGHTJUMP = 26,
|
||||
AS_LEFTJUMP = 27,
|
||||
AS_UPJUMP = 28,
|
||||
AS_FALLBACK = 29,
|
||||
AS_HANGLEFT = 30,
|
||||
AS_HANGRIGHT = 31,
|
||||
AS_SLIDEBACK = 32,
|
||||
AS_SURFTREAD = 33,
|
||||
AS_SURFSWIM = 34,
|
||||
AS_DIVE = 35,
|
||||
AS_PUSHBLOCK = 36,
|
||||
AS_PULLBLOCK = 37,
|
||||
AS_PPREADY = 38,
|
||||
AS_PICKUP = 39,
|
||||
AS_SWITCHON = 40,
|
||||
AS_SWITCHOFF = 41,
|
||||
AS_USEKEY = 42,
|
||||
AS_USEPUZZLE = 43,
|
||||
AS_UWDEATH = 44,
|
||||
AS_ROLL = 45,
|
||||
AS_SPECIAL = 46,
|
||||
AS_SURFBACK = 47,
|
||||
AS_SURFLEFT = 48,
|
||||
AS_SURFRIGHT = 49,
|
||||
AS_USEMIDAS = 50,
|
||||
AS_DIEMIDAS = 51,
|
||||
AS_SWANDIVE = 52,
|
||||
AS_FASTDIVE = 53,
|
||||
AS_GYMNAST = 54,
|
||||
AS_WATEROU = 55,
|
||||
AS_WALK = 0,
|
||||
AS_RUN = 1,
|
||||
AS_STOP = 2,
|
||||
AS_FORWARDJUMP = 3,
|
||||
AS_POSE = 4,
|
||||
AS_FASTBACK = 5,
|
||||
AS_TURN_R = 6,
|
||||
AS_TURN_L = 7,
|
||||
AS_DEATH = 8,
|
||||
AS_FASTFALL = 9,
|
||||
AS_HANG = 10,
|
||||
AS_REACH = 11,
|
||||
AS_SPLAT = 12,
|
||||
AS_TREAD = 13,
|
||||
AS_LAND = 14,
|
||||
AS_COMPRESS = 15,
|
||||
AS_BACK = 16,
|
||||
AS_SWIM = 17,
|
||||
AS_GLIDE = 18,
|
||||
AS_NULL = 19,
|
||||
AS_FASTTURN = 20,
|
||||
AS_STEPRIGHT = 21,
|
||||
AS_STEPLEFT = 22,
|
||||
AS_HIT = 23,
|
||||
AS_SLIDE = 24,
|
||||
AS_BACKJUMP = 25,
|
||||
AS_RIGHTJUMP = 26,
|
||||
AS_LEFTJUMP = 27,
|
||||
AS_UPJUMP = 28,
|
||||
AS_FALLBACK = 29,
|
||||
AS_HANGLEFT = 30,
|
||||
AS_HANGRIGHT = 31,
|
||||
AS_SLIDEBACK = 32,
|
||||
AS_SURFTREAD = 33,
|
||||
AS_SURFSWIM = 34,
|
||||
AS_DIVE = 35,
|
||||
AS_PUSHBLOCK = 36,
|
||||
AS_PULLBLOCK = 37,
|
||||
AS_PPREADY = 38,
|
||||
AS_PICKUP = 39,
|
||||
AS_SWITCHON = 40,
|
||||
AS_SWITCHOFF = 41,
|
||||
AS_USEKEY = 42,
|
||||
AS_USEPUZZLE = 43,
|
||||
AS_UWDEATH = 44,
|
||||
AS_ROLL = 45,
|
||||
AS_SPECIAL = 46,
|
||||
AS_SURFBACK = 47,
|
||||
AS_SURFLEFT = 48,
|
||||
AS_SURFRIGHT = 49,
|
||||
AS_USEMIDAS = 50,
|
||||
AS_DIEMIDAS = 51,
|
||||
AS_SWANDIVE = 52,
|
||||
AS_FASTDIVE = 53,
|
||||
AS_GYMNAST = 54,
|
||||
AS_WATEROU = 55,
|
||||
} LARA_STATES;
|
||||
|
||||
typedef enum {
|
||||
LG_ARMLESS = 0,
|
||||
LG_HANDSBUSY = 1,
|
||||
LG_DRAW = 2,
|
||||
LG_UNDRAW = 3,
|
||||
LG_READY = 4,
|
||||
LG_ARMLESS = 0,
|
||||
LG_HANDSBUSY = 1,
|
||||
LG_DRAW = 2,
|
||||
LG_UNDRAW = 3,
|
||||
LG_READY = 4,
|
||||
} LARA_GUN_STATES;
|
||||
|
||||
typedef enum {
|
||||
BORED_MOOD = 0,
|
||||
ATTACK_MOOD = 1,
|
||||
ESCAPE_MOOD = 2,
|
||||
STALK_MOOD = 3,
|
||||
BORED_MOOD = 0,
|
||||
ATTACK_MOOD = 1,
|
||||
ESCAPE_MOOD = 2,
|
||||
STALK_MOOD = 3,
|
||||
} MOOD_TYPE;
|
||||
|
||||
typedef enum {
|
||||
GBUF_RoomInfos = 11,
|
||||
GBUF_RoomMesh = 12,
|
||||
GBUF_RoomDoor = 13,
|
||||
GBUF_RoomFloor = 14,
|
||||
GBUF_RoomLights = 15,
|
||||
GBUF_RoomInfos = 11,
|
||||
GBUF_RoomMesh = 12,
|
||||
GBUF_RoomDoor = 13,
|
||||
GBUF_RoomFloor = 14,
|
||||
GBUF_RoomLights = 15,
|
||||
GBUF_RoomStaticMeshInfos = 16,
|
||||
GBUF_FloorData = 17,
|
||||
GBUF_Items = 18,
|
||||
GBUF_CreatureData = 33,
|
||||
GBUF_CreatureLot = 34,
|
||||
GBUF_FloorData = 17,
|
||||
GBUF_Items = 18,
|
||||
GBUF_CreatureData = 33,
|
||||
GBUF_CreatureLot = 34,
|
||||
} GAMEALLOC_BUFFER;
|
||||
|
||||
typedef enum {
|
||||
GYM = 0,
|
||||
LEVEL1 = 1, // Peru 1: Caves
|
||||
LEVEL2 = 2, // Peru 2: City of Vilcabamba
|
||||
LEVEL3A = 3, // Peru 3: The Lost Valley
|
||||
LEVEL3B = 4, // Peru 4: Tomb of Qualopec
|
||||
LEVEL4 = 5, // Greece 1: St Francis Folly
|
||||
LEVEL5 = 6, // Greece 2: Colosseum
|
||||
LEVEL6 = 7, // Greece 3: Place Midas
|
||||
LEVEL7A = 8, // Greece 4: Cistern
|
||||
LEVEL7B = 9, // Greece 5: Tomb of Tihocan
|
||||
LEVEL8A = 10, // Egypt 1: City of Khamoon
|
||||
LEVEL8B = 11, // Egypt 2: Obelisk of Khamoon
|
||||
LEVEL8C = 12, // Egypt 3: Sanctuary of Scion
|
||||
LEVEL10A = 13, // Lost island 1: Natla's Mines
|
||||
LEVEL10B = 14, // Lost island 2: Atlantis
|
||||
LEVEL10C = 15, // Lost island 3: The great pyramid
|
||||
CUTSCENE1 = 16,
|
||||
CUTSCENE2 = 17,
|
||||
CUTSCENE3 = 18,
|
||||
CUTSCENE4 = 19,
|
||||
TITLE = 20,
|
||||
CURRENT = 21,
|
||||
GYM = 0,
|
||||
LEVEL1 = 1, // Peru 1: Caves
|
||||
LEVEL2 = 2, // Peru 2: City of Vilcabamba
|
||||
LEVEL3A = 3, // Peru 3: The Lost Valley
|
||||
LEVEL3B = 4, // Peru 4: Tomb of Qualopec
|
||||
LEVEL4 = 5, // Greece 1: St Francis Folly
|
||||
LEVEL5 = 6, // Greece 2: Colosseum
|
||||
LEVEL6 = 7, // Greece 3: Place Midas
|
||||
LEVEL7A = 8, // Greece 4: Cistern
|
||||
LEVEL7B = 9, // Greece 5: Tomb of Tihocan
|
||||
LEVEL8A = 10, // Egypt 1: City of Khamoon
|
||||
LEVEL8B = 11, // Egypt 2: Obelisk of Khamoon
|
||||
LEVEL8C = 12, // Egypt 3: Sanctuary of Scion
|
||||
LEVEL10A = 13, // Lost island 1: Natla's Mines
|
||||
LEVEL10B = 14, // Lost island 2: Atlantis
|
||||
LEVEL10C = 15, // Lost island 3: The great pyramid
|
||||
CUTSCENE1 = 16,
|
||||
CUTSCENE2 = 17,
|
||||
CUTSCENE3 = 18,
|
||||
CUTSCENE4 = 19,
|
||||
TITLE = 20,
|
||||
CURRENT = 21,
|
||||
// UB_LEVEL1 = 22, // TRUB - Egypt
|
||||
// UB_LEVEL2 = 23, // TRUB - Temple of Cat
|
||||
// UB_LEVEL3 = 24,
|
||||
|
@ -159,35 +159,35 @@ typedef enum {
|
|||
NUMBER_OF_LEVELS = 22,
|
||||
} GAME_LEVELS;
|
||||
|
||||
#define IN_FORWARD (1<<0)
|
||||
#define IN_BACK (1<<1)
|
||||
#define IN_LEFT (1<<2)
|
||||
#define IN_RIGHT (1<<3)
|
||||
#define IN_JUMP (1<<4)
|
||||
#define IN_DRAW (1<<5)
|
||||
#define IN_ACTION (1<<6)
|
||||
#define IN_SLOW (1<<7)
|
||||
#define IN_OPTION (1<<8)
|
||||
#define IN_LOOK (1<<9)
|
||||
#define IN_STEPL (1<<10)
|
||||
#define IN_STEPR (1<<11)
|
||||
#define IN_ROLL (1<<12)
|
||||
#define IN_PAUSE (1<<13)
|
||||
#define IN_A (1<<14) // A to F are Debug thingys..
|
||||
#define IN_B (1<<15)
|
||||
#define IN_C (1<<16)
|
||||
#define IN_MENUBACK (1<<17)
|
||||
#define IN_UP (1<<18)
|
||||
#define IN_DOWN (1<<19)
|
||||
#define IN_SELECT (1<<20)
|
||||
#define IN_DESELECT (1<<21)
|
||||
#define IN_SAVE (1<<22)
|
||||
#define IN_LOAD (1<<23)
|
||||
#define IN_ACTION_AUTO (1<<24)
|
||||
#define IN_CHEAT (1<<25)
|
||||
#define IN_D (1<<26)
|
||||
#define IN_E (1<<27)
|
||||
#define IN_F (1<<28)
|
||||
#define IN_FORWARD (1 << 0)
|
||||
#define IN_BACK (1 << 1)
|
||||
#define IN_LEFT (1 << 2)
|
||||
#define IN_RIGHT (1 << 3)
|
||||
#define IN_JUMP (1 << 4)
|
||||
#define IN_DRAW (1 << 5)
|
||||
#define IN_ACTION (1 << 6)
|
||||
#define IN_SLOW (1 << 7)
|
||||
#define IN_OPTION (1 << 8)
|
||||
#define IN_LOOK (1 << 9)
|
||||
#define IN_STEPL (1 << 10)
|
||||
#define IN_STEPR (1 << 11)
|
||||
#define IN_ROLL (1 << 12)
|
||||
#define IN_PAUSE (1 << 13)
|
||||
#define IN_A (1 << 14)
|
||||
#define IN_B (1 << 15)
|
||||
#define IN_C (1 << 16)
|
||||
#define IN_MENUBACK (1 << 17)
|
||||
#define IN_UP (1 << 18)
|
||||
#define IN_DOWN (1 << 19)
|
||||
#define IN_SELECT (1 << 20)
|
||||
#define IN_DESELECT (1 << 21)
|
||||
#define IN_SAVE (1 << 22)
|
||||
#define IN_LOAD (1 << 23)
|
||||
#define IN_ACTION_AUTO (1 << 24)
|
||||
#define IN_CHEAT (1 << 25)
|
||||
#define IN_D (1 << 26)
|
||||
#define IN_E (1 << 27)
|
||||
#define IN_F (1 << 28)
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
|
@ -256,11 +256,11 @@ typedef struct {
|
|||
} MESH_INFO;
|
||||
|
||||
typedef struct {
|
||||
/* 0000 */ int16_t *data;
|
||||
/* 0004 */ DOOR_INFOS *doors;
|
||||
/* 0008 */ FLOOR_INFO *floor;
|
||||
/* 000C */ LIGHT_INFO *light;
|
||||
/* 0010 */ MESH_INFO *mesh;
|
||||
/* 0000 */ int16_t* data;
|
||||
/* 0004 */ DOOR_INFOS* doors;
|
||||
/* 0008 */ FLOOR_INFO* floor;
|
||||
/* 000C */ LIGHT_INFO* light;
|
||||
/* 0010 */ MESH_INFO* mesh;
|
||||
/* 0014 */ int32_t x;
|
||||
/* 0018 */ int32_t y;
|
||||
/* 001C */ int32_t z;
|
||||
|
@ -313,7 +313,7 @@ typedef struct {
|
|||
/* 0026 */ int16_t timer;
|
||||
/* 0028 */ int16_t flags;
|
||||
/* 002A */ int16_t shade;
|
||||
/* 002C */ void *data;
|
||||
/* 002C */ void* data;
|
||||
/* 0030 */ PHD_3DPOS pos;
|
||||
/* 0042 */ uint16_t active : 1;
|
||||
/* */ uint16_t status : 2;
|
||||
|
@ -325,7 +325,7 @@ typedef struct {
|
|||
} ITEM_INFO;
|
||||
|
||||
typedef struct {
|
||||
/* 0000 */ uint16_t *frame_base;
|
||||
/* 0000 */ uint16_t* frame_base;
|
||||
/* 0004 */ uint16_t frame_number;
|
||||
/* 0006 */ uint16_t lock;
|
||||
/* 0008 */ PHD_ANGLE y_rot;
|
||||
|
@ -351,7 +351,7 @@ typedef struct {
|
|||
} BOX_NODE;
|
||||
|
||||
typedef struct {
|
||||
/* 0000 */ BOX_NODE *node;
|
||||
/* 0000 */ BOX_NODE* node;
|
||||
/* 0004 */ int16_t head;
|
||||
/* 0006 */ int16_t tail;
|
||||
/* 0008 */ uint16_t search_number;
|
||||
|
@ -381,10 +381,10 @@ typedef struct {
|
|||
/* 0016 */ int16_t death_count;
|
||||
/* 0018 */ int16_t current_active;
|
||||
/* 001A */ int16_t spaz_effect_count;
|
||||
/* 001C */ UNKNOWN_STRUCT *spaz_effect;
|
||||
/* 001C */ UNKNOWN_STRUCT* spaz_effect;
|
||||
/* 0020 */ int32_t mesh_effects;
|
||||
/* 0024 */ int16_t *mesh_ptrs[15];
|
||||
/* 0060 */ ITEM_INFO *target;
|
||||
/* 0024 */ int16_t* mesh_ptrs[15];
|
||||
/* 0060 */ ITEM_INFO* target;
|
||||
/* 0064 */ PHD_ANGLE target_angles[2];
|
||||
/* 0068 */ int16_t turn_rate;
|
||||
/* 006A */ int16_t move_angle;
|
||||
|
@ -473,9 +473,9 @@ typedef struct {
|
|||
/* 0014 */ int16_t flash_rate;
|
||||
/* 0016 */ int16_t flash_count;
|
||||
/* 0018 */ int16_t bgnd_colour;
|
||||
/* 001A */ SG_COL *bgnd_gour;
|
||||
/* 001A */ SG_COL* bgnd_gour;
|
||||
/* 001E */ int16_t outl_colour;
|
||||
/* 0020 */ SG_COL *outl_gour;
|
||||
/* 0020 */ SG_COL* outl_gour;
|
||||
/* 0024 */ int16_t bgnd_size_x;
|
||||
/* 0026 */ int16_t bgnd_size_y;
|
||||
/* 0028 */ int16_t bgnd_off_x;
|
||||
|
@ -483,7 +483,7 @@ typedef struct {
|
|||
/* 002C */ int16_t bgnd_off_z;
|
||||
/* 002E */ int32_t scale_h;
|
||||
/* 0032 */ int32_t scale_v;
|
||||
/* 0034 */ char *string;
|
||||
/* 0034 */ char* string;
|
||||
/* 0038 end */
|
||||
} TEXTSTRING;
|
||||
|
||||
|
|
57
src/util.c
57
src/util.c
|
@ -1,10 +1,11 @@
|
|||
#include <windows.h>
|
||||
#include "util.h"
|
||||
#include <dbghelp.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include "util.h"
|
||||
#include <windows.h>
|
||||
|
||||
void tr1m_inject_func(void *from, void *to) {
|
||||
void tr1m_inject_func(void* from, void* to)
|
||||
{
|
||||
DWORD tmp;
|
||||
TRACE("Patching %p to %p", from, to);
|
||||
VirtualProtect(from, sizeof(JMP), PAGE_EXECUTE_READWRITE, &tmp);
|
||||
|
@ -19,7 +20,8 @@ void tr1m_inject_func(void *from, void *to) {
|
|||
//((JMP*)(from))->offset = (DWORD)(to) - ((DWORD)(from) + sizeof(JMP));
|
||||
}
|
||||
|
||||
void tr1m_print_stack_trace() {
|
||||
void tr1m_print_stack_trace()
|
||||
{
|
||||
const size_t MaxNameLen = 255;
|
||||
BOOL result;
|
||||
HANDLE process;
|
||||
|
@ -28,10 +30,9 @@ void tr1m_print_stack_trace() {
|
|||
STACKFRAME64 stack;
|
||||
ULONG frame;
|
||||
DWORD64 displacement;
|
||||
IMAGEHLP_SYMBOL64 *pSymbol = malloc(
|
||||
sizeof(IMAGEHLP_SYMBOL64) + (MaxNameLen + 1) * sizeof(TCHAR)
|
||||
);
|
||||
char *name = malloc(MaxNameLen + 1);
|
||||
IMAGEHLP_SYMBOL64* pSymbol =
|
||||
malloc(sizeof(IMAGEHLP_SYMBOL64) + (MaxNameLen + 1) * sizeof(TCHAR));
|
||||
char* name = malloc(MaxNameLen + 1);
|
||||
|
||||
RtlCaptureContext(&context);
|
||||
memset(&stack, 0, sizeof(STACKFRAME64));
|
||||
|
@ -46,42 +47,28 @@ void tr1m_print_stack_trace() {
|
|||
stack.AddrFrame.Offset = context.Ebp;
|
||||
stack.AddrFrame.Mode = AddrModeFlat;
|
||||
|
||||
for (frame = 0; ; frame++) {
|
||||
for (frame = 0;; frame++) {
|
||||
result = StackWalk64(
|
||||
IMAGE_FILE_MACHINE_I386,
|
||||
process,
|
||||
thread,
|
||||
&stack,
|
||||
&context,
|
||||
NULL,
|
||||
SymFunctionTableAccess64,
|
||||
SymGetModuleBase64,
|
||||
NULL
|
||||
);
|
||||
IMAGE_FILE_MACHINE_I386, process, thread, &stack, &context, NULL,
|
||||
SymFunctionTableAccess64, SymGetModuleBase64, NULL);
|
||||
|
||||
pSymbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
|
||||
pSymbol->MaxNameLength = MaxNameLen;
|
||||
|
||||
SymGetSymFromAddr64(
|
||||
process, (ULONG64)stack.AddrPC.Offset, &displacement, pSymbol
|
||||
);
|
||||
process, (ULONG64)stack.AddrPC.Offset, &displacement, pSymbol);
|
||||
UnDecorateSymbolName(
|
||||
pSymbol->Name, ( PSTR )name, MaxNameLen, UNDNAME_COMPLETE
|
||||
);
|
||||
pSymbol->Name, (PSTR)name, MaxNameLen, UNDNAME_COMPLETE);
|
||||
|
||||
TRACE(
|
||||
"Frame %lu:\n"
|
||||
" Symbol name: %s\n"
|
||||
" PC address: 0x%08LX\n"
|
||||
" Stack address: 0x%08LX\n"
|
||||
" Frame address: 0x%08LX\n"
|
||||
"\n",
|
||||
frame,
|
||||
pSymbol->Name,
|
||||
(ULONG64)stack.AddrPC.Offset,
|
||||
(ULONG64)stack.AddrStack.Offset,
|
||||
(ULONG64)stack.AddrFrame.Offset
|
||||
);
|
||||
"Frame %lu:\n"
|
||||
" Symbol name: %s\n"
|
||||
" PC address: 0x%08LX\n"
|
||||
" Stack address: 0x%08LX\n"
|
||||
" Frame address: 0x%08LX\n"
|
||||
"\n",
|
||||
frame, pSymbol->Name, (ULONG64)stack.AddrPC.Offset,
|
||||
(ULONG64)stack.AddrStack.Offset, (ULONG64)stack.AddrFrame.Offset);
|
||||
|
||||
if (!result) {
|
||||
break;
|
||||
|
|
32
src/util.h
32
src/util.h
|
@ -3,32 +3,34 @@
|
|||
|
||||
#define FEATURE_NOCD_DATA
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
int8_t opcode; // must be 0xE9
|
||||
uint8_t opcode; // must be 0xE9
|
||||
uint32_t offset;
|
||||
} JMP;
|
||||
#pragma pack(pop)
|
||||
|
||||
#define TRACE(...) { \
|
||||
printf("%s:%d %s ", __FILE__, __LINE__, __func__); \
|
||||
printf(__VA_ARGS__); \
|
||||
printf("\n"); \
|
||||
fflush(stdout); \
|
||||
}
|
||||
#define TRACE(...) \
|
||||
{ \
|
||||
printf("%s:%d %s ", __FILE__, __LINE__, __func__); \
|
||||
printf(__VA_ARGS__); \
|
||||
printf("\n"); \
|
||||
fflush(stdout); \
|
||||
}
|
||||
|
||||
#define VAR_U_(address, type) (*(type*)(address))
|
||||
#define VAR_I_(address, type, value) (*(type*)(address))
|
||||
#define ARRAY_(address, type, length) (*(type(*)length)(address))
|
||||
#define VAR_U_(address, type) (*(type*)(address))
|
||||
#define VAR_I_(address, type, value) (*(type*)(address))
|
||||
#define ARRAY_(address, type, length) (*(type(*) length)(address))
|
||||
|
||||
void tr1m_inject_func(void *from, void *to);
|
||||
void tr1m_inject_func(void* from, void* to);
|
||||
void tr1m_print_stack_trace();
|
||||
|
||||
#define INJECT(from, to) { \
|
||||
tr1m_inject_func((void*)from, (void*)to); \
|
||||
}
|
||||
#define INJECT(from, to) \
|
||||
{ \
|
||||
tr1m_inject_func((void*)from, (void*)to); \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue