Skip to content

Commit

Permalink
Implement all Underworld menu functions
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Jan 21, 2024
1 parent db47a29 commit eb68761
Show file tree
Hide file tree
Showing 17 changed files with 387 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ Instance* Game::GetPlayerInstance()

GameTracker* Game::GetGameTracker()
{
return (GameTracker*)0x838330;
return (GameTracker*)GET_ADDRESS(0x10E5370, 0x838330, 0x00E7F088);
}

void GAMELOOP_ExitGame(char* name, GameTracker* gameTracker, int doneType)
void GAMELOOP_RequestLevelChangeByName(char* name, GameTracker* gameTracker, int doneType)
{
Hooking::Call(0xC61CFA, name, gameTracker, doneType);
auto addr = GET_ADDRESS(0x451970, 0xC61CFA, 0x5DF8C0);

Hooking::Call(addr, name, gameTracker, doneType);
}
54 changes: 53 additions & 1 deletion src/game/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct WipeInfo
float wipeStep;
};

#ifndef TR8
struct GameTracker
{
menu_t* menu;
Expand Down Expand Up @@ -50,6 +51,57 @@ struct GameTracker

float timeMult;
};
#else
struct GameTracker
{
int field_0;
int field_4;
Level* level;
Instance* playerInstance;

int debugFlags;
int debugFlags2;
int debugFlags3;
int debugFlags4;

int displayFrameCount;
int field_24;
int field_28;
int field_2C;
int field_30;
int field_34;

char baseAreaName[128];
char field_B8;
char field_B9;
char field_BA;

char gameMode;
char cheatMode;

char field_BD;
char field_BE;
char field_BF;
int StreamUnitID;
int field_C4;
int field_C8;
int field_CC;
int field_D0;
int field_D4;
int field_D8;
int field_DC;
int field_E0;
int field_E4;
int field_E8;
int field_EC;
int field_F0;
int field_F4;
int field_F8;
int field_FC;

float timeMult;
};
#endif

class Game
{
Expand All @@ -58,4 +110,4 @@ class Game
static GameTracker* GetGameTracker();
};

void GAMELOOP_ExitGame(char* name, GameTracker* gameTracker, int doneType);
void GAMELOOP_RequestLevelChangeByName(char* name, GameTracker* gameTracker, int doneType);
4 changes: 3 additions & 1 deletion src/input/Input.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "Input.h"

#include "util/Hooking.h"

void Input::DisableInput(bool disable)
{
*(bool*)0x8551A9 = disable;
*(bool*)GET_ADDRESS(0x1101689, 0x8551A9, 0xA02B79) = disable;
}
16 changes: 16 additions & 0 deletions src/instance/Animation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "Animation.h"
#include "util/Hooking.h"

void G2EmulationInstanceSetAnimation(Instance* instance, int CurrentSection, int NewAnim, int NewFrame, int Frames)
{
auto addr = GET_ADDRESS(0x4DEC30, 0x4DE690, 0x5B1EA0);

Hooking::Call(addr, instance, CurrentSection, NewAnim, NewFrame, Frames);
}

void G2EmulationInstanceSetMode(Instance* instance, int CurrentSection, int Mode)
{
auto addr = GET_ADDRESS(0x4DED90, 0x4DE7F0, 0x5B1F50);

Hooking::Call(addr, instance, CurrentSection, Mode);
}
6 changes: 6 additions & 0 deletions src/instance/Animation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "Instance.h"

void G2EmulationInstanceSetAnimation(Instance* instance, int CurrentSection, int NewAnim, int NewFrame, int Frames);
void G2EmulationInstanceSetMode(Instance* instance, int CurrentSection, int Mode);
22 changes: 20 additions & 2 deletions src/instance/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,28 @@

void INSTANCE_Post(Instance* instance, int message, int data)
{
Hooking::Call(0x4580B0, instance, message, data);
auto addr = GET_ADDRESS(0x455510, 0x4580B0, 0x5B3750);

Hooking::Call(addr, instance, message, data);
}

void INSTANCE_HideUnhideDrawGroup(Instance* instance, int drawGroup, int on)
{
Hooking::Call(0x4319B0, instance, drawGroup, on);
auto addr = GET_ADDRESS(0x456230, 0x4319B0, 0x5B3DD0);

Hooking::Call(addr, instance, drawGroup, on);
}

void INSTANCE_ReallyRemoveInstance(Instance* instance, int reset, bool keepSave)
{
auto addr = GET_ADDRESS(0x4575B0, 0x45A3A0, 0x5BC4E0);

Hooking::Call(addr, instance, reset, keepSave);
}

Instance* INSTANCE_BirthObjectNoParent(unsigned int unitID, cdc::Vector3* position, cdc::Euler* rotation, IntroData* introData, Object* object, int modelNum, int initEffects)
{
auto addr = GET_ADDRESS(0x458990, 0x45BA90, 0x5BD0F0);

return Hooking::CallReturn<Instance*>(addr, unitID, position, rotation, introData, object, modelNum, initEffects);
}
34 changes: 33 additions & 1 deletion src/instance/Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ struct Intro
{
};

struct IntroData
{
};

struct ObjectData
{
unsigned __int16 version;
Expand All @@ -32,6 +36,7 @@ struct CharacterProxy;

struct Instance;

#ifndef TR8
struct BaseInstance
{
NodeType node;
Expand Down Expand Up @@ -73,7 +78,34 @@ struct Instance : BaseInstance
char pad2[12];

int introUniqueID;

char pad3[104];

void* extraData;
};
#else
struct Instance
{
NodeType node;

Instance* next;
Instance* prev;

Object* object;

char pad1[12];

cdc::Vector3 position;
cdc::Euler rotation;

char pad2[24];

int introUniqueID;
};
#endif

void INSTANCE_Post(Instance* instance, int message, int data);
void INSTANCE_HideUnhideDrawGroup(Instance* instance, int drawGroup, int on);
void INSTANCE_HideUnhideDrawGroup(Instance* instance, int drawGroup, int on);
void INSTANCE_ReallyRemoveInstance(Instance* instance, int reset, bool keepSave);

Instance* INSTANCE_BirthObjectNoParent(unsigned int unitID, cdc::Vector3* position, cdc::Euler* rotation, IntroData* introData, Object* object, int modelNum, int initEffects);
3 changes: 2 additions & 1 deletion src/instance/Instances.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "Instances.h"
#include "util/Hooking.h"

void Instances::Iterate(std::function<void(Instance*)> callback)
{
auto first = *(Instance**)0x817D64;
auto first = *(Instance**)GET_ADDRESS(0x10C5AA4, 0x817D64, 0xD98D54);

for (auto instance = first; instance != nullptr; instance = instance->next)
{
Expand Down
16 changes: 15 additions & 1 deletion src/instance/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct AnimFxHeader;
struct AnimScriptObject;
struct ObjectBase;

#ifndef TR8
struct Object
{
int oflags;
Expand Down Expand Up @@ -39,4 +40,17 @@ struct Object

void* data;
char* name;
};
};
#else
struct Object
{
char pad1[58];

__int16 numModels;
__int16 numAnims;

char pad2[34];

char* name;
};
#endif
16 changes: 16 additions & 0 deletions src/level/Stream.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "Stream.h"
#include "util/Hooking.h"

ObjectTracker* STREAM_GetObjectTrackerByName(char* name)
{
auto addr = GET_ADDRESS(0x5D4270, 0x5DA260, 0x5C17D0);

return Hooking::CallReturn<ObjectTracker*>(addr, name);
}

bool STREAM_PollLoadQueue()
{
auto addr = GET_ADDRESS(0x5D51C0, 0x5DB190, 0x5C1DA0);

return Hooking::CallReturn<bool>(addr);
}
23 changes: 23 additions & 0 deletions src/level/Stream.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include "instance/Object.h"

#if TRAE || TR7
#define MAX_UNIT_NAME_LENGTH 20
#else
#define MAX_UNIT_NAME_LENGTH 128
#endif

struct ResolveObject;

struct ObjectTracker
{
ResolveObject* resolveObj;
char* objectName;
Object* object;
__int16 objectID;
__int16 objectStatus;
};

ObjectTracker* STREAM_GetObjectTrackerByName(char* name);
bool STREAM_PollLoadQueue();
Loading

0 comments on commit eb68761

Please sign in to comment.