From 919b537e28b69372ae10a23cf18fb846f07f2386 Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Wed, 24 Nov 2021 17:25:23 +0300 Subject: [PATCH] Added FT demo data support. Tested with .006 ,.020 RC2, there might be more versions out there. Fixed mds2midi. Ref #22. --- SpaceCadetPinball/TBall.cpp | 7 +++++-- SpaceCadetPinball/TTableLayer.cpp | 6 ++++-- SpaceCadetPinball/fullscrn.cpp | 4 ++-- SpaceCadetPinball/midi.cpp | 7 +++++-- SpaceCadetPinball/partman.cpp | 5 +++++ SpaceCadetPinball/pb.cpp | 19 ++++++++++++------- SpaceCadetPinball/pb.h | 2 +- 7 files changed, 34 insertions(+), 16 deletions(-) diff --git a/SpaceCadetPinball/TBall.cpp b/SpaceCadetPinball/TBall.cpp index 4b37e92..4bf91d0 100644 --- a/SpaceCadetPinball/TBall.cpp +++ b/SpaceCadetPinball/TBall.cpp @@ -34,9 +34,12 @@ TBall::TBall(TPinballTable* table) : TPinballComponent(table, -1, false) ListBitmap = new std::vector(); /*Full tilt: ball is ballN, where N[0,2] resolution*/ - if (pb::FullTiltMode) - ballGroupName[4] = '0' + fullscrn::GetResolution(); auto groupIndex = loader::query_handle(ballGroupName); + if (groupIndex < 0) + { + ballGroupName[4] = '0' + fullscrn::GetResolution(); + groupIndex = loader::query_handle(ballGroupName); + } Offset = *loader::query_float_attribute(groupIndex, 0, 500); diff --git a/SpaceCadetPinball/TTableLayer.cpp b/SpaceCadetPinball/TTableLayer.cpp index e45ba36..f804bb9 100644 --- a/SpaceCadetPinball/TTableLayer.cpp +++ b/SpaceCadetPinball/TTableLayer.cpp @@ -54,11 +54,13 @@ TTableLayer::TTableLayer(TPinballTable* table): TCollisionComponent(table, -1, f GraityDirX = cos(PinballTable->GravityAnglY) * sin(PinballTable->GravityAngleX) * PinballTable->GravityDirVectMult; GraityDirY = sin(PinballTable->GravityAnglY) * sin(PinballTable->GravityAngleX) * PinballTable->GravityDirVectMult; - auto angleMultArr = loader::query_float_attribute(groupIndex, 0, 701); /*Full tilt hack - GraityMult should be 0.2*/ - if (angleMultArr && !pb::FullTiltMode) + if (!pb::FullTiltMode && !pb::FullTiltDemoMode) + { + auto angleMultArr = loader::query_float_attribute(groupIndex, 0, 701); GraityMult = *angleMultArr; + } else GraityMult = 0.2f; diff --git a/SpaceCadetPinball/fullscrn.cpp b/SpaceCadetPinball/fullscrn.cpp index 4db62bf..a2e23d7 100644 --- a/SpaceCadetPinball/fullscrn.cpp +++ b/SpaceCadetPinball/fullscrn.cpp @@ -95,7 +95,7 @@ int fullscrn::GetResolution() void fullscrn::SetResolution(int value) { - if (!pb::FullTiltMode) + if (!pb::FullTiltMode || pb::FullTiltDemoMode) value = 0; assertm(value >= 0 && value <= 2, "Resolution value out of bounds"); resolution = value; @@ -103,7 +103,7 @@ void fullscrn::SetResolution(int value) int fullscrn::GetMaxResolution() { - return pb::FullTiltMode ? 2 : 0; + return pb::FullTiltMode && !pb::FullTiltDemoMode ? 2 : 0; } void fullscrn::window_size_changed() diff --git a/SpaceCadetPinball/midi.cpp b/SpaceCadetPinball/midi.cpp index 9adc940..b045524 100644 --- a/SpaceCadetPinball/midi.cpp +++ b/SpaceCadetPinball/midi.cpp @@ -56,6 +56,10 @@ int midi::music_init() track1 = load_track("TABA1"); track2 = load_track("TABA2"); track3 = load_track("TABA3"); + + // FT demo .006 has only one music track, but it is nearly 9 min. long + if (!track1 && pb::FullTiltDemoMode) + track1 = load_track("DEMO"); } else { @@ -271,8 +275,7 @@ std::vector* midi::MdsToMidi(std::string file) // Delta time is in variable quantity, Big Endian uint32_t deltaVarLen; auto count = ToVariableLen(delta, deltaVarLen); - deltaVarLen = SwapByteOrderInt(deltaVarLen); - auto deltaData = reinterpret_cast(&deltaVarLen) + 4 - count; + auto deltaData = reinterpret_cast(&deltaVarLen); midiBytes.insert(midiBytes.end(), deltaData, deltaData + count); switch (event.iEvent >> 24) diff --git a/SpaceCadetPinball/partman.cpp b/SpaceCadetPinball/partman.cpp index 2901d74..43eeb5f 100644 --- a/SpaceCadetPinball/partman.cpp +++ b/SpaceCadetPinball/partman.cpp @@ -86,6 +86,11 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode) { zMapResolution = LRead(fileHandle); fieldSize--; + + // -1 means universal resolution, maybe. FT demo .006 is the only known user. + if (zMapResolution == 0xff) + zMapResolution = 0; + assertm(zMapResolution <= 2, "partman: zMap resolution out of bounds"); } diff --git a/SpaceCadetPinball/pb.cpp b/SpaceCadetPinball/pb.cpp index 02bfd05..350bd55 100644 --- a/SpaceCadetPinball/pb.cpp +++ b/SpaceCadetPinball/pb.cpp @@ -32,7 +32,7 @@ DatFile* pb::record_table = nullptr; int pb::time_ticks = 0, pb::demo_mode = 0, pb::game_mode = 2; float pb::mode_countdown_, pb::time_now = 0, pb::time_next = 0, pb::ball_speed_limit, pb::time_ticks_remainder = 0; high_score_struct pb::highscore_table[5]; -bool pb::FullTiltMode = false, pb::cheat_mode = false; +bool pb::FullTiltMode = false, pb::FullTiltDemoMode = false, pb::cheat_mode = false; std::string pb::DatFileName; @@ -121,14 +121,16 @@ int pb::uninit() void pb::SelectDatFile(std::array dataSearchPaths) { DatFileName.clear(); + FullTiltDemoMode = FullTiltMode = false; - std::string datFileNames[2] + std::string datFileNames[3] { "CADET.DAT", - options::get_string("Pinball Data", pinball::get_rc_string(168, 0)) + options::get_string("Pinball Data", pinball::get_rc_string(168, 0)), + "DEMO.DAT", }; - // Default game data test order: CADET.DAT, PINBALL.DAT + // Default game data test order: CADET.DAT, PINBALL.DAT, DEMO.DAT if (options::Options.Prefer3DPBGameData) std::swap(datFileNames[0], datFileNames[1]); for (auto path : dataSearchPaths) @@ -136,16 +138,19 @@ void pb::SelectDatFile(std::array dataSearchPaths) if (DatFileName.empty() && path) { pinball::BasePath = path; - for (int i = 0; i < 2; i++) + for (auto datFileName : datFileNames) { - auto datFileName = datFileNames[i]; auto datFilePath = pinball::make_path_name(datFileName); auto datFile = fopenu(datFilePath.c_str(), "r"); if (datFile) { fclose(datFile); DatFileName = datFileName; - FullTiltMode = datFileName == "CADET.DAT"; + if (datFileName == "CADET.DAT") + FullTiltMode = true; + if (datFileName == "DEMO.DAT") + FullTiltDemoMode = FullTiltMode = true; + printf("Loading game from: %s\n", datFilePath.c_str()); break; } diff --git a/SpaceCadetPinball/pb.h b/SpaceCadetPinball/pb.h index 5c2a173..40a62af 100644 --- a/SpaceCadetPinball/pb.h +++ b/SpaceCadetPinball/pb.h @@ -40,7 +40,7 @@ public: static DatFile* record_table; static TPinballTable* MainTable; static high_score_struct highscore_table[5]; - static bool FullTiltMode; + static bool FullTiltMode, FullTiltDemoMode; static std::string DatFileName; static int init();