2023-06-30 19:33:59 -04:00
|
|
|
#include "legoutil.h"
|
|
|
|
|
2023-12-29 10:22:18 -05:00
|
|
|
#include "legoomni.h"
|
|
|
|
#include "legoworld.h"
|
|
|
|
#include "mxdsaction.h"
|
2023-09-29 12:42:15 -04:00
|
|
|
#include "mxomni.h"
|
2023-12-29 10:22:18 -05:00
|
|
|
#include "mxstreamer.h"
|
2023-07-02 04:05:49 -04:00
|
|
|
#include "mxtypes.h"
|
|
|
|
|
2023-12-29 10:22:18 -05:00
|
|
|
#include <process.h>
|
2023-09-27 15:16:46 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
2024-02-02 20:03:52 -05:00
|
|
|
DECOMP_SIZE_ASSERT(NamedTexture, 0x14)
|
|
|
|
|
2024-01-26 17:52:03 -05:00
|
|
|
// STUB: LEGO1 0x1003e050
|
|
|
|
void FUN_1003e050(LegoAnimPresenter* p_presenter)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1003e300
|
2024-01-17 11:53:53 -05:00
|
|
|
Extra::ActionType MatchActionString(const char* p_str)
|
2023-10-24 19:38:27 -04:00
|
|
|
{
|
2024-01-17 11:53:53 -05:00
|
|
|
Extra::ActionType result = Extra::ActionType::e_unknown;
|
2023-09-27 15:16:46 -04:00
|
|
|
|
2024-02-01 15:42:10 -05:00
|
|
|
if (!strcmpi("openram", p_str)) {
|
2024-01-17 11:53:53 -05:00
|
|
|
result = Extra::ActionType::e_openram;
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
|
|
|
else if (!strcmpi("opendisk", p_str)) {
|
2024-01-17 11:53:53 -05:00
|
|
|
result = Extra::ActionType::e_opendisk;
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
|
|
|
else if (!strcmpi("close", p_str)) {
|
2024-01-17 11:53:53 -05:00
|
|
|
result = Extra::ActionType::e_close;
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
|
|
|
else if (!strcmpi("start", p_str)) {
|
2024-01-17 11:53:53 -05:00
|
|
|
result = Extra::ActionType::e_start;
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
|
|
|
else if (!strcmpi("stop", p_str)) {
|
2024-01-17 11:53:53 -05:00
|
|
|
result = Extra::ActionType::e_stop;
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
|
|
|
else if (!strcmpi("run", p_str)) {
|
2024-01-17 11:53:53 -05:00
|
|
|
result = Extra::ActionType::e_run;
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
|
|
|
else if (!strcmpi("exit", p_str)) {
|
2024-01-17 11:53:53 -05:00
|
|
|
result = Extra::ActionType::e_exit;
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
|
|
|
else if (!strcmpi("enable", p_str)) {
|
2024-01-17 11:53:53 -05:00
|
|
|
result = Extra::ActionType::e_enable;
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
|
|
|
else if (!strcmpi("disable", p_str)) {
|
2024-01-17 11:53:53 -05:00
|
|
|
result = Extra::ActionType::e_disable;
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
|
|
|
else if (!strcmpi("notify", p_str)) {
|
2024-01-17 11:53:53 -05:00
|
|
|
result = Extra::ActionType::e_notify;
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
2023-09-27 15:16:46 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
return result;
|
2023-09-27 15:16:46 -04:00
|
|
|
}
|
|
|
|
|
2023-12-29 10:22:18 -05:00
|
|
|
MxBool CheckIfEntityExists(MxBool p_enable, const char* p_filename, MxS32 p_entityId);
|
|
|
|
void NotifyEntity(const char* p_filename, MxS32 p_entityId, LegoEntity* p_sender);
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1003e430
|
2024-01-17 11:53:53 -05:00
|
|
|
void InvokeAction(Extra::ActionType p_actionId, MxAtomId& p_pAtom, int p_targetEntityId, LegoEntity* p_sender)
|
2023-12-29 10:22:18 -05:00
|
|
|
{
|
|
|
|
MxDSAction action;
|
|
|
|
action.SetAtomId(p_pAtom);
|
|
|
|
action.SetObjectId(p_targetEntityId);
|
|
|
|
|
|
|
|
switch (p_actionId) {
|
2024-01-17 11:53:53 -05:00
|
|
|
case Extra::ActionType::e_opendisk:
|
2023-12-29 10:22:18 -05:00
|
|
|
if (!CheckIfEntityExists(TRUE, p_pAtom.GetInternal(), p_targetEntityId)) {
|
2024-01-17 11:53:53 -05:00
|
|
|
Streamer()->Open(p_pAtom.GetInternal(), MxStreamer::e_diskStream);
|
2023-12-29 10:22:18 -05:00
|
|
|
Start(&action);
|
|
|
|
}
|
|
|
|
break;
|
2024-01-17 11:53:53 -05:00
|
|
|
case Extra::ActionType::e_openram:
|
2023-12-29 10:22:18 -05:00
|
|
|
if (!CheckIfEntityExists(TRUE, p_pAtom.GetInternal(), p_targetEntityId)) {
|
|
|
|
Streamer()->Open(p_pAtom.GetInternal(), MxStreamer::e_RAMStream);
|
|
|
|
Start(&action);
|
|
|
|
}
|
|
|
|
break;
|
2024-01-17 11:53:53 -05:00
|
|
|
case Extra::ActionType::e_close:
|
2023-12-29 10:22:18 -05:00
|
|
|
action.SetUnknown24(-2);
|
|
|
|
DeleteObject(action);
|
|
|
|
Streamer()->Close(p_pAtom.GetInternal());
|
|
|
|
break;
|
2024-01-17 11:53:53 -05:00
|
|
|
case Extra::ActionType::e_start:
|
2023-12-29 10:22:18 -05:00
|
|
|
if (!CheckIfEntityExists(TRUE, p_pAtom.GetInternal(), p_targetEntityId)) {
|
|
|
|
Start(&action);
|
|
|
|
}
|
|
|
|
break;
|
2024-01-17 11:53:53 -05:00
|
|
|
case Extra::ActionType::e_stop:
|
2023-12-29 10:22:18 -05:00
|
|
|
action.SetUnknown24(-2);
|
|
|
|
if (!FUN_1003ee00(p_pAtom, p_targetEntityId)) {
|
|
|
|
DeleteObject(action);
|
|
|
|
}
|
|
|
|
break;
|
2024-01-17 11:53:53 -05:00
|
|
|
case Extra::ActionType::e_run:
|
2023-12-29 10:22:18 -05:00
|
|
|
_spawnl(0, "\\lego\\sources\\main\\main.exe", "\\lego\\sources\\main\\main.exe", "/script", &p_pAtom, 0);
|
|
|
|
break;
|
2024-01-17 11:53:53 -05:00
|
|
|
case Extra::ActionType::e_exit:
|
2023-12-29 10:22:18 -05:00
|
|
|
Lego()->SetExit(TRUE);
|
|
|
|
break;
|
2024-01-17 11:53:53 -05:00
|
|
|
case Extra::ActionType::e_enable:
|
2023-12-29 10:22:18 -05:00
|
|
|
CheckIfEntityExists(TRUE, p_pAtom.GetInternal(), p_targetEntityId);
|
|
|
|
break;
|
2024-01-17 11:53:53 -05:00
|
|
|
case Extra::ActionType::e_disable:
|
2023-12-29 10:22:18 -05:00
|
|
|
CheckIfEntityExists(FALSE, p_pAtom.GetInternal(), p_targetEntityId);
|
|
|
|
break;
|
2024-01-17 11:53:53 -05:00
|
|
|
case Extra::ActionType::e_notify:
|
2023-12-29 10:22:18 -05:00
|
|
|
NotifyEntity(p_pAtom.GetInternal(), p_targetEntityId, p_sender);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1003e670
|
|
|
|
MxBool CheckIfEntityExists(MxBool p_enable, const char* p_filename, MxS32 p_entityId)
|
|
|
|
{
|
2024-01-26 16:00:02 -05:00
|
|
|
LegoWorld* world = FindWorld(MxAtomId(p_filename, e_lowerCase2), p_entityId);
|
|
|
|
|
2023-12-29 10:22:18 -05:00
|
|
|
if (world) {
|
2024-02-02 12:18:46 -05:00
|
|
|
world->Enable(p_enable);
|
2023-12-29 10:22:18 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// STUB: LEGO1 0x1003e700
|
|
|
|
void NotifyEntity(const char* p_filename, MxS32 p_entityId, LegoEntity* p_sender)
|
2023-12-14 11:50:29 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1003eae0
|
2023-12-13 05:48:14 -05:00
|
|
|
void ConvertHSVToRGB(float p_h, float p_s, float p_v, float* p_rOut, float* p_bOut, float* p_gOut)
|
2023-06-30 19:33:59 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
double calc;
|
|
|
|
double p;
|
2023-12-13 05:48:14 -05:00
|
|
|
MxLong hueIndex;
|
2023-10-24 19:38:27 -04:00
|
|
|
double v9;
|
|
|
|
double v12;
|
|
|
|
double v13;
|
2023-07-02 04:02:05 -04:00
|
|
|
|
2023-12-13 05:48:14 -05:00
|
|
|
double sDbl = p_s;
|
2023-07-02 04:02:05 -04:00
|
|
|
|
2024-02-01 15:42:10 -05:00
|
|
|
if (p_s > 0.5f) {
|
2023-12-13 05:48:14 -05:00
|
|
|
calc = (1.0f - p_v) * p_s + p_v;
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
|
|
|
else {
|
2023-12-13 05:48:14 -05:00
|
|
|
calc = (p_v + 1.0) * sDbl;
|
2024-02-01 15:42:10 -05:00
|
|
|
}
|
2023-10-24 19:38:27 -04:00
|
|
|
if (calc <= 0.0) {
|
2023-12-13 05:48:14 -05:00
|
|
|
*p_gOut = 0.0f;
|
|
|
|
*p_bOut = 0.0f;
|
|
|
|
*p_rOut = 0.0f;
|
2023-10-24 19:38:27 -04:00
|
|
|
return;
|
|
|
|
}
|
2023-12-13 05:48:14 -05:00
|
|
|
p = p_s * 2.0f - calc;
|
|
|
|
hueIndex = p_h * 6.0;
|
|
|
|
v9 = (p_h * 6.0 - (float) hueIndex) * ((calc - p) / calc) * calc;
|
2023-10-24 19:38:27 -04:00
|
|
|
v12 = p + v9;
|
|
|
|
v13 = calc - v9;
|
2023-12-13 05:48:14 -05:00
|
|
|
switch (hueIndex) {
|
2023-10-24 19:38:27 -04:00
|
|
|
case 0:
|
2023-12-13 05:48:14 -05:00
|
|
|
*p_rOut = calc;
|
|
|
|
*p_bOut = v12;
|
|
|
|
*p_gOut = p;
|
2023-10-24 19:38:27 -04:00
|
|
|
break;
|
|
|
|
case 1:
|
2023-12-13 05:48:14 -05:00
|
|
|
*p_rOut = v13;
|
|
|
|
*p_bOut = calc;
|
|
|
|
*p_gOut = p;
|
2023-10-24 19:38:27 -04:00
|
|
|
break;
|
|
|
|
case 2:
|
2023-12-13 05:48:14 -05:00
|
|
|
*p_rOut = p;
|
|
|
|
*p_bOut = calc;
|
|
|
|
*p_gOut = v12;
|
2023-10-24 19:38:27 -04:00
|
|
|
break;
|
|
|
|
case 3:
|
2023-12-13 05:48:14 -05:00
|
|
|
*p_rOut = p;
|
|
|
|
*p_bOut = v13;
|
|
|
|
*p_gOut = calc;
|
2023-10-24 19:38:27 -04:00
|
|
|
break;
|
|
|
|
case 4:
|
2023-12-13 05:48:14 -05:00
|
|
|
*p_rOut = v12;
|
|
|
|
*p_bOut = p;
|
|
|
|
*p_gOut = calc;
|
2023-10-24 19:38:27 -04:00
|
|
|
break;
|
|
|
|
case 5:
|
2023-12-13 05:48:14 -05:00
|
|
|
*p_rOut = calc;
|
|
|
|
*p_bOut = p;
|
|
|
|
*p_gOut = v13;
|
2023-10-24 19:38:27 -04:00
|
|
|
break;
|
|
|
|
case 6:
|
2023-12-13 05:48:14 -05:00
|
|
|
*p_rOut = calc;
|
|
|
|
*p_bOut = p;
|
|
|
|
*p_gOut = v13;
|
2023-10-24 19:38:27 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2023-07-02 04:05:49 -04:00
|
|
|
}
|
2023-09-29 12:42:15 -04:00
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// STUB: LEGO1 0x1003ee00
|
2023-12-29 10:22:18 -05:00
|
|
|
MxBool FUN_1003ee00(MxAtomId& p_atomId, MxS32 p_id)
|
2023-10-24 08:37:02 -04:00
|
|
|
{
|
2023-12-29 10:22:18 -05:00
|
|
|
return TRUE;
|
2023-10-24 08:37:02 -04:00
|
|
|
}
|
|
|
|
|
2024-01-31 07:34:36 -05:00
|
|
|
// FUNCTION: LEGO1 0x1003ee80
|
|
|
|
MxBool RemoveFromWorld(MxAtomId& p_entityAtom, MxS32 p_entityId, MxAtomId& p_worldAtom, MxS32 p_worldEntityId)
|
|
|
|
{
|
|
|
|
LegoWorld* world = FindWorld(p_worldAtom, p_worldEntityId);
|
|
|
|
|
|
|
|
if (world) {
|
|
|
|
MxCore* object = world->Find(p_entityAtom, p_entityId);
|
|
|
|
|
|
|
|
if (object) {
|
|
|
|
world->Remove(object);
|
|
|
|
|
|
|
|
if (!object->IsA("MxPresenter")) {
|
|
|
|
delete object;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (((MxPresenter*) object)->GetAction()) {
|
|
|
|
FUN_100b7220(((MxPresenter*) object)->GetAction(), MxDSAction::c_world, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
((MxPresenter*) object)->EndAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2023-12-15 18:11:34 -05:00
|
|
|
// STUB: LEGO1 0x1003ef00
|
|
|
|
void FUN_1003ef00(MxBool)
|
|
|
|
{
|
|
|
|
// TODO (something related to animation manager)
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1003ef40
|
2023-09-29 12:42:15 -04:00
|
|
|
void SetAppCursor(WPARAM p_wparam)
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
PostMessageA(MxOmni::GetInstance()->GetWindowHandle(), 0x5400, p_wparam, 0);
|
2023-09-29 12:42:15 -04:00
|
|
|
}
|
2023-12-14 11:50:29 -05:00
|
|
|
|
|
|
|
// STUB: LEGO1 0x1003ef60
|
|
|
|
MxBool FUN_1003ef60()
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
2024-02-02 20:03:52 -05:00
|
|
|
|
|
|
|
// STUB: LEGO1 0x1003f3b0
|
|
|
|
NamedTexture* ReadNamedTexture(LegoFile* p_file)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// STUB: LEGO1 0x1003f540
|
|
|
|
void FUN_1003f540(LegoFile* p_file, const char* p_filename)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1003f8a0
|
|
|
|
void WriteNamedTexture(LegoFile* p_file, NamedTexture* p_texture)
|
|
|
|
{
|
|
|
|
p_file->FUN_10006030(*p_texture->GetName());
|
|
|
|
p_texture->GetTexture()->Write(p_file);
|
|
|
|
}
|