Skip to content

Commit ae71ca7

Browse files
committed
Trying to debug for F2.5
1 parent 5b575e4 commit ae71ca7

4 files changed

Lines changed: 71 additions & 6 deletions

File tree

Actions.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
void Extension::LoadJSON(TCHAR const *JSON, int flags)
55
{
66
json_settings settings = {0};
7-
settings.settings = (flags ? json_relaxed_commas : 0);
8-
char Error[128];
7+
settings.settings = (flags ? json_enable_comments : 0);
8+
char Error[json_error_max];
99
#ifdef UNICODE
1010
std::string json = UTF8fromUnicode(JSON);
1111
if(json.empty())
@@ -69,3 +69,31 @@ void Extension::GotoRoot()
6969
{
7070
current = root;
7171
}
72+
73+
#include <sstream>
74+
void Extension::DebugWindow()
75+
{
76+
#ifdef UNICODE
77+
std::wostringstream oss;
78+
#else
79+
std::ostringstream oss;
80+
#endif
81+
oss << _T("IsString: ") << std::boolalpha << IsString() << std::endl;
82+
oss << _T("IsInteger: ") << std::boolalpha << IsInteger() << std::endl;
83+
oss << _T("IsDouble: ") << std::boolalpha << IsDouble() << std::endl;
84+
oss << _T("IsObject: ") << std::boolalpha << IsObject() << std::endl;
85+
oss << _T("IsArray: ") << std::boolalpha << IsArray() << std::endl;
86+
oss << _T("IsBoolean: ") << std::boolalpha << IsBoolean() << std::endl;
87+
oss << _T("IsNull: ") << std::boolalpha << IsNull() << std::endl;
88+
oss << _T("IsTrue: ") << std::boolalpha << IsTrue() << std::endl;
89+
oss << std::endl;
90+
oss << _T("GetError: ") << GetError() << std::endl;
91+
oss << _T("GetString: ") << GetString() << std::endl;
92+
oss << _T("GetInteger: ") << GetInteger() << std::endl;
93+
oss << _T("GetLong: ") << GetLong() << std::endl;
94+
oss << _T("GetFloat: ") << GetFloat() << std::endl;
95+
oss << _T("GetDouble: ") << GetDouble() << std::endl;
96+
oss << _T("GetNumValues: ") << GetNumValues() << std::endl;
97+
oss << _T("GetBoolNum: ") << GetBoolNum() << std::endl;
98+
MessageBox(NULL, oss.str().c_str(), _T("JSON Object Debug"), MB_OK);
99+
}

Ext.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"Name": "JSON Object",
55
"Author": "LB",
6-
"Copyright": "Copyright © 2013 LB-Stuff",
6+
"Copyright": "Copyright © 2014 LB-Stuff",
77
"Comment": "Allows you to parse JSON files from strings, and in the future will allow you to modify and generate JSONs as strings.\nRequested by Rushino.\nThanks to Phi and ConceptGame for helping with debugging.",
88
"URL": "http://www.LB-Stuff.com/",
99
"Help": "Help/JSON Object/Help.chm",
@@ -22,6 +22,7 @@
2222
[4, "Go to Root"]
2323
],
2424
"Separator",
25+
[5, "Debug Window"],
2526
[0, "Modification", true],
2627
"Separator"
2728
],
@@ -60,7 +61,7 @@
6061
"Parameters":
6162
[
6263
["String", "JSON (not a file path, the actual JSON)"],
63-
["Integer", "Flags (0 for none): currently only one: 1=relaxed commas"]
64+
["Integer", "Flags (0 for none): currently only one: 1=enable comments"]
6465
]
6566
},
6667
{ "Title": "Enter Object named (%0)",
@@ -78,6 +79,8 @@
7879
{ "Title": "Go Up to Parent"
7980
},
8081
{ "Title": "Go to Root"
82+
},
83+
{ "Title": "Debug Window"
8184
}
8285
],
8386
"Conditions":

Extension.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
*/
3131
Extension::Extension(RD *rd, SerializedED *SED, createObjectInfo *COB) : rd(rd), rh(rd->rHo.hoAdRunHeader), Runtime(rd)
3232
{
33+
if(SDK->ActionFunctions.size() < 6)
34+
{
35+
MessageBox(NULL, _T("ActionFunctions vector too small!"), _T("JSON Object Debug"), MB_OK);
36+
}
3337
//Link all your action/condition/expression functions
3438
//to their IDs to match the IDs in the JSON here.
3539
LinkAction(0, LoadJSON);
@@ -38,6 +42,12 @@ Extension::Extension(RD *rd, SerializedED *SED, createObjectInfo *COB) : rd(rd),
3842
LinkAction(3, GoUp);
3943
LinkAction(4, GotoRoot);
4044

45+
LinkAction(5, DebugWindow);
46+
if(!SDK->ActionFunctions[5])
47+
{
48+
MessageBox(NULL, _T("Function not linked after linking!"), _T("JSON Object Debug"), MB_OK);
49+
}
50+
4151
LinkCondition(0, OnError);
4252
LinkCondition(1, IsString);
4353
LinkCondition(2, IsInteger);
@@ -186,17 +196,38 @@ bool Extension::Load(HANDLE File)
186196
* to let you know that the ID is unlinked, or you
187197
* may just want to use unlinked A/C/Es as a feature.
188198
*/
199+
#include <sstream>
189200
void Extension::Action(int ID, RD *rd, long param1, long param2)
190201
{
202+
#ifdef UNICODE
203+
std::wostringstream oss;
204+
#else
205+
std::ostringstream oss;
206+
#endif
207+
oss << _T("Unlinked Action, ID = ") << ID << std::endl;
208+
MessageBox(NULL, oss.str().c_str(), _T("JSON Object Debug"), MB_OK);
191209
}
192210

193211
long Extension::Condition(int ID, RD *rd, long param1, long param2)
194212
{
213+
#ifdef UNICODE
214+
std::wostringstream oss;
215+
#else
216+
std::ostringstream oss;
217+
#endif
218+
oss << _T("Unlinked Condition, ID = ") << ID << std::endl;
219+
MessageBox(NULL, oss.str().c_str(), _T("JSON Object Debug"), MB_OK);
195220
return false; //hopefully StringComparison (PARAM_CMPSTRING) is not used, or this may crash
196221
}
197222

198223
long Extension::Expression(int ID, RD *rd, long param)
199224
{
225+
#ifdef UNICODE
226+
std::wostringstream oss;
227+
#else
228+
std::ostringstream oss;
229+
#endif
230+
oss << _T("Unlinked Expression, ID = ") << ID << std::endl;
231+
MessageBox(NULL, oss.str().c_str(), _T("JSON Object Debug"), MB_OK);
200232
return long(_T("")); //so that unlinked expressions that return strings won't crash
201233
}
202-

Extension.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ class Extension
8080
std::string UTF8fromUnicode(std::wstring s)
8181
{
8282
int size = WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, NULL, 0, NULL, NULL);
83-
char *buf = new char[size];
83+
char *buf = new char[size]();
8484
if(!WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, buf, size, NULL, NULL))
8585
{
86+
delete[] buf;
8687
return "";
8788
}
8889
std::string t (buf);
@@ -100,6 +101,8 @@ class Extension
100101
void GoUp();
101102
void GotoRoot();
102103

104+
void DebugWindow();
105+
103106
//Conditions
104107
bool OnError(); //0
105108
bool IsString();

0 commit comments

Comments
 (0)