-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginSetup.h
More file actions
110 lines (95 loc) · 3.7 KB
/
PluginSetup.h
File metadata and controls
110 lines (95 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#pragma once
#include <fstream>
#include <iterator>
#include <string>
#include <Windows.h>
#include <vector>
#include <direct.h>
#include <ostream>
#include <sstream>
#include <iomanip>
//#define DEBUG // enables more prints
#include "SDK/SDK.hpp"
#include "LH/Filesystem.h"
HINSTANCE DllHandle;
static std::string gPluginName = "yourName.ModTemplateName.yytk"; // Mandatory name, used to register to core
static std::string cfgFilename = Filesys::GetCurrentDir() + "\\options.ini"; // this will use the pre-existing GameMaker created options.ini file
static std::string SectionName = "TemplateMod"; // your mod's settings section in the ini file, this can theoretically be the same as gPluginname if you want to
static std::string KeyName = "MySetting"; // one setting to save, make as many as needed
DllExport std::string GetPluginName() // For yytk, mandatory
{
return gPluginName;
}
// Some useful functions that don't fit into their own category (may be restructured in the future)
namespace Misc {
void Print(std::string s, Color c = CLR_DEFAULT)
{
PrintMessage(c, (gPluginName + ": " + s).c_str());
}
void PrintDbg(std::string s, std::string func, int line, Color c)
{
PrintMessage(c, (gPluginName + ": " + s + " (" + func + ":" + std::to_string(line) + ")").c_str());
}
// checks if a string s contains a substring subs
bool StringHasSubstr(std::string s, std::string subs)
{
if (s.find(subs) != std::string::npos) {
return true;
}
return false;
}
//https://www.techiedelight.com/check-if-a-string-ends-with-another-string-in-cpp/
bool StringEndsWith(std::string const& str, std::string const& suffix) {
if (str.length() < suffix.length()) {
return false;
}
return str.compare(str.length() - suffix.length(), suffix.length(), suffix) == 0;
}
}
namespace Binds {
void GetInstanceVariables(YYRValue& arr, YYRValue inst)
{
CallBuiltin(arr, "variable_instance_get_names", nullptr, nullptr, { inst });
}
YYRValue CallBuiltin(const std::string name, CInstance* self, CInstance* other, const std::vector<YYRValue> args)
{
YYRValue var;
CallBuiltin(var, name, self, other, args);
return var;
}
YYRValue CallBuiltinA(const std::string name, const std::vector<YYRValue> args)
{
YYRValue var;
CallBuiltin(var, name, nullptr, nullptr, args);
return var;
}
void PrintArrayInstanceVariables(YYRValue var, YYRValue inst, Color c = Color::CLR_DEFAULT)
{
YYRValue len;
YYRValue item;
YYRValue content;
YYRValue type;
CallBuiltin(len, "array_length_1d", nullptr, nullptr, { var });
for (int i = 0; i < (int)len; i++)
{
CallBuiltin(item, "array_get", nullptr, nullptr, { var, (double)i });
CallBuiltin(content, "variable_instance_get", nullptr, nullptr, { inst, static_cast<const char*>(item) });
CallBuiltin(type, "typeof", nullptr, nullptr, { content });
std::string typestr = std::string(static_cast<const char*>(type));
std::string message = std::string(static_cast<const char*>(item)) + " -> " + std::string(static_cast<const char*>(type));
if (typestr == "number")
{
message += " : " + std::to_string((int)content);
}
else if (typestr == "bool")
{
message += " : " + std::to_string(int((bool)content));
}
else if (typestr == "string")
{
message += " : " + std::string(static_cast<const char*>(content));
}
Misc::Print(message);
}
}
}