Skip to content

Commit

Permalink
Fix Bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gamepiaynmo committed Oct 12, 2020
1 parent 3fda7fa commit 96b0c96
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 81 deletions.
4 changes: 2 additions & 2 deletions BML.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>WIN32;_DEBUG;BML_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;BML_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<StructMemberAlignment>Default</StructMemberAlignment>
Expand Down Expand Up @@ -133,7 +133,7 @@
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;BML_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;BML_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<StructMemberAlignment>Default</StructMemberAlignment>
Expand Down
56 changes: 47 additions & 9 deletions BMLMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "Commands.h"
#include "Config.h"
#include "Util.h"
#include <locale>
#include <codecvt>

using namespace ScriptHelper;

Expand Down Expand Up @@ -130,6 +132,12 @@ void BMLMod::OnLoadScript(CKSTRING filename, CKBehavior* script) {

if (!strcmp(script->GetName(), "Levelinit_build"))
OnEditScript_Levelinit_build(script);

if (m_fixLifeBall) {
if (!strcmp(script->GetName(), "P_Extra_Life_Particle_Blob Script")
|| !strcmp(script->GetName(), "P_Extra_Life_Particle_Fizz Script"))
OnEditScript_ExtraLife_Fix(script);
}
}

void BMLMod::OnEditScript_Base_DefaultLevel(CKBehavior* script) {
Expand Down Expand Up @@ -513,6 +521,14 @@ void BMLMod::OnEditScript_Levelinit_build(CKBehavior* script) {
m_mapFile = objLoad->GetInputParameter(0)->GetDirectSource();
}

void BMLMod::OnEditScript_ExtraLife_Fix(CKBehavior* script) {
CKBehavior* emitter = FindFirstBB(script, "SphericalParticleSystem");
emitter->CreateInputParameter("Real-Time Mode", CKPGUID_BOOL)
->SetDirectSource(CreateParamValue<CKBOOL>(script, "Real-Time Mode", CKPGUID_BOOL, 1));
emitter->CreateInputParameter("DeltaTime", CKPGUID_FLOAT)
->SetDirectSource(CreateParamValue<float>(script, "DeltaTime", CKPGUID_FLOAT, 20.0f));
}

void BMLMod::OnCheatEnabled(bool enable) {
if (enable) {
SetParamValue(m_ballForce[0], m_ballCheat[0]->GetKey());
Expand Down Expand Up @@ -571,6 +587,10 @@ void BMLMod::OnLoad() {
m_showSR->SetComment("Show SR Timer above Time Score");
m_showSR->SetDefaultBoolean(true);

m_fixLifeBall = GetConfig()->GetProperty("Misc", "FixLifeBallFreeze");
m_fixLifeBall->SetComment("Game won't freeze when picking up life balls");
m_fixLifeBall->SetDefaultBoolean(true);

GetConfig()->SetCategoryComment("Debug", "Debug Utilities");
m_suicide = GetConfig()->GetProperty("Debug", "Suicide");
m_suicide->SetComment("Suicide");
Expand Down Expand Up @@ -1292,12 +1312,29 @@ GuiCustomMap::GuiCustomMap(BMLMod* mod) : GuiList(), m_mod(mod) {
m_right->SetPosition(Vx2DVector(0.6238f, 0.4f));

AddTextLabel("M_Opt_Mods_Title", "Custom Maps", ExecuteBB::GAMEFONT_02, 0.35f, 0.07f, 0.3f, 0.1f);
using convert_type = std::codecvt_byname<wchar_t, char, std::mbstate_t>;
std::wstring_convert<convert_type, wchar_t> converter(new convert_type("zh-CN"));

for (auto& f : std::filesystem::recursive_directory_iterator("..\\ModLoader\\Maps")) {
if (f.status().type() == std::filesystem::file_type::regular) {
std::string filename = f.path().filename().string();
std::transform(filename.begin(), filename.end(), filename.begin(), tolower);
if (std::filesystem::path(filename).extension() == ".nmo") {
m_maps.push_back({ f.path().filename().string(), Text2Pinyin(filename) });
std::string ext = f.path().extension().string();
std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
if (ext == ".nmo") {
MapInfo info;
try {
info.displayname = f.path().stem().string();
info.searchname = Text2Pinyin(info.displayname);
info.filepath = "..\\ModLoader\\Maps\\" + info.displayname + ".nmo";
}
catch (std::system_error e) {
std::string filename = converter.to_bytes(f.path().stem().wstring());
info.displayname = info.searchname = Text2Pinyin(filename);
info.filepath = "..\\ModLoader\\Cache\\Maps\\" + info.displayname + ".nmo";
std::filesystem::copy_file(std::filesystem::absolute(f.path()), info.filepath);
}

std::transform(info.searchname.begin(), info.searchname.end(), info.searchname.begin(), tolower);
m_maps.push_back(info);
}
}
}
Expand All @@ -1316,8 +1353,8 @@ GuiCustomMap::GuiCustomMap(BMLMod* mod) : GuiList(), m_mod(mod) {
std::transform(text.begin(), text.end(), text.begin(), tolower);

for (auto& p : m_maps) {
if (text.length() == 0 || p.second.find(text) != std::string::npos) {
m_searchRes.push_back(p.first);
if (text.length() == 0 || p.searchname.find(text) != std::string::npos) {
m_searchRes.push_back(&p);
}
}
m_size = m_searchRes.size();
Expand All @@ -1327,7 +1364,7 @@ GuiCustomMap::GuiCustomMap(BMLMod* mod) : GuiList(), m_mod(mod) {

std::sort(m_maps.begin(), m_maps.end());
for (auto& p : m_maps)
m_searchRes.push_back(p.first);
m_searchRes.push_back(&p);
Init(m_searchRes.size(), 10);
SetVisible(false);
}
Expand All @@ -1336,10 +1373,11 @@ BGui::Button* GuiCustomMap::CreateButton(int index) {
m_texts.push_back(AddText(("M_Opt_ModMenu_" + std::to_string(index)).c_str(), "", 0.44f, 0.23f + 0.06f * index, 0.3f, 0.05f));
return AddLevelButton(("M_Opt_ModMenu_" + std::to_string(index)).c_str(), "", 0.23f + 0.06f * index, 0.4031f, [this, index]() {
GuiList::Exit();
SetParamString(m_mod->m_mapFile, ("..\\ModLoader\\Maps\\" + m_searchRes[m_curpage * m_maxsize + index]).c_str());
SetParamString(m_mod->m_mapFile, m_searchRes[m_curpage * m_maxsize + index]->filepath.c_str());
SetParamValue(m_mod->m_loadCustom, TRUE);
int level = rand() % 10 + 2;
m_mod->m_curLevel->SetElementValue(0, 0, &level);
level--;
SetParamValue(m_mod->m_levelRow, level);

CKContext* ctx = m_mod->m_bml->GetCKContext();
Expand Down Expand Up @@ -1373,7 +1411,7 @@ void GuiCustomMap::SetPage(int page) {
for (int i = 0; i < m_maxsize; i++)
m_texts[i]->SetVisible(i < size);
for (int i = 0; i < size; i++)
m_texts[i]->SetText(m_searchRes[page * m_maxsize + i].c_str());
m_texts[i]->SetText(m_searchRes[page * m_maxsize + i]->displayname.c_str());
m_mod->m_bml->AddTimer(1u, [this, page]() { m_exit->SetVisible(page == 0); });
}

Expand Down
16 changes: 13 additions & 3 deletions BMLMod.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,15 @@ class GuiCustomMap : public GuiList {
virtual void Exit() override;

private:
std::vector<std::pair<std::string, std::string>> m_maps;
std::vector<std::string> m_searchRes;
struct MapInfo {
std::string displayname, searchname, filepath;
bool operator <(const MapInfo& o) {
return displayname < o.displayname;
}
};

std::vector<MapInfo> m_maps;
std::vector<MapInfo*> m_searchRes;
std::vector<BGui::Text*> m_texts;
BGui::Input* m_searchBar = nullptr;
BGui::Button* m_exit = nullptr;
Expand Down Expand Up @@ -136,7 +143,8 @@ class BMLMod : public IMod {
virtual CKSTRING GetVersion() override { return BML_VERSION; }
virtual CKSTRING GetName() override { return "Ballance Mod Loader"; }
virtual CKSTRING GetAuthor() override { return "Gamepiaynmo & YingChe"; }
virtual CKSTRING GetDescription() override { return "Implementation of functions provided by Ballance Mod Loader."; }
virtual CKSTRING GetDescription() override { return "Implementation of functions provided by Ballance Mod Loader."
"\n\n https://github.com/Gamepiaynmo/BallanceModLoader"; }
DECLARE_BML_VERSION;

virtual void OnLoad() override;
Expand Down Expand Up @@ -175,6 +183,7 @@ class BMLMod : public IMod {
void OnEditScript_Gameplay_Energy(CKBehavior* script);
void OnEditScript_Gameplay_Events(CKBehavior* script);
void OnEditScript_Levelinit_build(CKBehavior* script);
void OnEditScript_ExtraLife_Fix(CKBehavior* script);

void OnCmdEdit(CKDWORD key);

Expand Down Expand Up @@ -206,6 +215,7 @@ class BMLMod : public IMod {
IProperty* m_unlockRes;
IProperty* m_showFPS;
IProperty* m_showSR;
IProperty* m_fixLifeBall;

IProperty* m_ballCheat[2];
IProperty* m_suicide;
Expand Down
2 changes: 1 addition & 1 deletion BuildVer.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define BML_MAJOR_VER 0
#define BML_MINOR_VER 3
#define BML_BUILD_VER 25
#define BML_BUILD_VER 28
24 changes: 18 additions & 6 deletions Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Vx2DVector InputHook::m_lastMousePosition;

CKMaterial* m_up = nullptr, * m_over = nullptr, * m_inactive = nullptr, * m_field = nullptr, * m_caret = nullptr, * m_highlight = nullptr;
CKGroup* all_sound = nullptr;
CKSTRING text_font = "微软雅黑";
CKSTRING g_text_font = nullptr;
CKSTRING g_avail_fonts[] = { "Microsoft YaHei UI", "Microsoft YaHei" };

CKBOOL InputHook::IsKeyDown(CKDWORD iKey, CKDWORD* oStamp) {
CKBOOL res = InputHook::oIsKeyDown(iKey, oStamp);
Expand Down Expand Up @@ -278,7 +279,7 @@ namespace BGui {
m_sprite->SetZOrder(20);
m_sprite->SetTextColor(0xffffffff);
m_sprite->SetAlign(CKSPRITETEXT_ALIGNMENT(CKSPRITETEXT_VCENTER | CKSPRITETEXT_LEFT));
m_sprite->SetFont(text_font, ctx->GetPlayerRenderContext()->GetHeight() / 85, 400);
m_sprite->SetFont(g_text_font, ctx->GetPlayerRenderContext()->GetHeight() / 85, 400);
}

Text::~Text() {
Expand All @@ -287,7 +288,7 @@ namespace BGui {

void Text::UpdateFont() {
CKContext* ctx = ModLoader::m_instance->GetCKContext();
m_sprite->SetFont(text_font, ctx->GetPlayerRenderContext()->GetHeight() / 85, 400);
m_sprite->SetFont(g_text_font, ctx->GetPlayerRenderContext()->GetHeight() / 85, 400);
}

Vx2DVector Text::GetPosition() {
Expand Down Expand Up @@ -941,10 +942,21 @@ namespace BGui {

CKParameterManager* pm = ModLoader::m_instance->GetParameterManager();
CKEnumStruct* data = pm->GetEnumDescByType(pm->ParameterGuidToType(CKPGUID_FONTNAME));
for (int i = 0; i < data->GetNumEnums(); i++) {
if (!strcmp(data->GetEnumDescription(i), "站酷高端黑"))
text_font = "站酷高端黑";
for (CKSTRING avail_font : g_avail_fonts) {
for (int i = 0; i < data->GetNumEnums(); i++) {
CKSTRING fontname = data->GetEnumDescription(i);
if (!strcmp(fontname, avail_font)) {
g_text_font = avail_font;
break;
}
}

if (g_text_font)
break;
}

if (!g_text_font)
g_text_font = "";
}

void Gui::OnScreenModeChanged() {
Expand Down
3 changes: 3 additions & 0 deletions IBML.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,7 @@ class BML_EXPORT IBML : public IMessageReceiver {
bool frozen, bool enableColl, bool calcMassCenter, float linearDamp, float rotDamp) = 0;
virtual void RegisterTrafo(CKSTRING modulName) = 0;
virtual void RegisterModul(CKSTRING modulName) = 0;

virtual int GetModCount() = 0;
virtual class IMod* GetMod(int index) = 0;
};
27 changes: 14 additions & 13 deletions IMod.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@
#define DECLARE_BML_VERSION \
virtual BMLVersion GetBMLVersion() override { return { BML_MAJOR_VER, BML_MINOR_VER, BML_BUILD_VER }; }

struct BMLVersion {
BMLVersion() : major(BML_MAJOR_VER), minor(BML_MINOR_VER), build(BML_BUILD_VER) {}
BMLVersion(int mj, int mn, int bd) : major(mj), minor(mn), build(bd) {}
int major, minor, build;
bool operator <(BMLVersion& o) {
if (major == o.major) {
if (minor == o.minor)
return build < o.build;
return minor < o.minor;
}
return major < o.major;
}
};

class BML_EXPORT IMod : public IMessageReceiver {
public:
IMod(IBML* bml) : m_bml(bml) {};
virtual ~IMod();

struct BMLVersion {
BMLVersion(int mj, int mn, int bd) : major(mj), minor(mn), build(bd) {}
int major, minor, build;
bool operator <(BMLVersion& o) {
if (major == o.major) {
if (minor == o.minor)
return build < o.build;
return minor < o.minor;
}
return major < o.major;
}
};

virtual CKSTRING GetID() = 0;
virtual CKSTRING GetVersion() = 0;
virtual CKSTRING GetName() = 0;
Expand Down
Loading

0 comments on commit 96b0c96

Please sign in to comment.