-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanHack_FileIO.cpp
124 lines (124 loc) · 3.01 KB
/
cleanHack_FileIO.cpp
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "G.h"
void G::mLoadHack( void )
{
s32 mode = 0, index, count;
xStr txt, text, path, file, name;
xStrT st;
xAStr array;
HACK* hack = new HACK;
CODE code;
u32 tmp;
tree_T->DeleteAllItems();
xTreeID root, doNotModifyThisTreeId;
gGetHackFile( path, file );
wxTextFile file_TF;
file_TF.Open( file );
mNewHack( GetHackRoot(), wxT( "(m)" ), hack, doNotModifyThisTreeId );
for
(
text = file_TF.GetFirstLine();
!file_TF.Eof();
text = file_TF.GetNextLine()
)
{
switch ( mode )
{
case 0: case 2:
if ( text.StartsWith( wxT( "\"" ) ) )
{
if ( mode == 2 )
{
index = 0;
count = array.GetCount();
for ( ; index < count; )
{
BuildCode( code, index, array );
hack->NewCode( code );
}
if ( hack->id == 0u ) mSetHack( root, hack );
else mNewHack( root, name, hack, doNotModifyThisTreeId );
}
hack->Clear();
array.Clear();
st.SetString( text, wxT( '"' ) );
st.GetNextToken();
name = st.GetNextToken();
mode = 1;
}
else if ( mode == 2 ) array.Add( text );
break;
case 1:
hack->id = GetHex( text.Mid( 4, 4 ) );
tmp = GetHex( text.Left( 4 ) );
hack->use = ( ( tmp & HACK_USE ) > 0u );
hack->useRB = ( ( tmp & HACK_RB ) > 0u );
if ( hack->id != 0u )
{
tmp = GetHex( text.Mid( 13, 4 ), 2u );
root = mFindHack( tmp );
}
else root = GetHackRoot();
mode = 2;
}
}
if ( mode == 2 )
{
index = 0;
count = array.GetCount();
for ( ; index < count; )
{
BuildCode( code, index, array );
hack->NewCode( code );
}
if ( hack->id == 0u ) mSetHack( root, hack );
else mNewHack( root, name, hack, doNotModifyThisTreeId );
}
delete hack;
tree_T->SelectItem( GetHackRoot() );
}
void G::mSaveHack( void )
{
xStr path, file;
u16 id = 0u;
gGetHackFile( path, file );
hack_TF.Open( file );
hack_TF.Clear();
mSaveHack( GetHackRoot(), id, 0u );
hack_TF.Write( wxTextFileType_Dos );
hack_TF.Close();
}
void G::mSaveHack( xTreeID root, u16 &id, u16 parentID )
{
HACK* hack = mGetHack( root );
xStr text = tree_T->GetItemText( root );
u16 head = 0u;
if ( hack->use ) head += HACK_USE;
if ( hack->useRB ) head += HACK_RB;
hack_TF.AddLine( wxT( '"' ) + text + wxT( '"' ), wxTextFileType_Dos );
text.Printf( hex16 + hex16 + wxT( " 0000" ) + hex16, head, id, parentID );
hack_TF.AddLine( text, wxTextFileType_Dos );
xAStr array;
s16 iCount = hack->GetCount();
s16 j, jCount;
for ( s16 i = 0; i < iCount; ++i )
{
array = BuildCode( ( *hack )[ i ] );
jCount = array.GetCount();
for ( j = 0; j < jCount; ++j )
hack_TF.AddLine( array[ j ], wxTextFileType_Dos );
}
// Iterate through children
parentID = id;
++id;
xTreeID kid;
xTreeIDV cookie;
for
(
kid = tree_T->GetFirstChild( root, cookie );
kid.IsOk();
kid = tree_T->GetNextChild( root, cookie )
)
{
mSaveHack( kid, id, parentID );
}
}