-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathendianness.c
180 lines (151 loc) · 4.19 KB
/
endianness.c
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include <assert.h>
#include <Buzz_inc.h>
#include <externs.h>
// Need these functions to always exist
uint32_t _Swap32bit(uint32_t value)
{
return (value >> 24)
| ((value >> 8) & 0x0000FF00)
| ((value << 8) & 0x00FF0000)
| (value << 24);
}
uint16_t _Swap16bit(uint16_t value)
{
return (value << 8) | (value >> 8);
}
float _SwapFloat(float value)
{
union
{
float f;
unsigned char b[4];
} dat1, dat2;
dat1.f = value;
dat2.b[0] = dat1.b[3];
dat2.b[1] = dat1.b[2];
dat2.b[2] = dat1.b[1];
dat2.b[3] = dat1.b[0];
return dat2.f;
}
// This will swap all the player structures
void _SwapGameDat(void)
{
i16 i, j;
ui32 val_ui32;
memcpy (&val_ui32, Data->EMark, 4);
val_ui32 = _Swap32bit (val_ui32);
memcpy (Data->EMark, &val_ui32, 4);
Data->Checksum = _Swap32bit(Data->Checksum);
for (j = 0; j < 28; j++)
{
Data->Prestige[j].Points[0] =
_Swap16bit(Data->Prestige[j].Points[0]);
Data->Prestige[j].Points[1] =
_Swap16bit(Data->Prestige[j].Points[1]);
}
for (j = 0; j < 2; j++)
{
Data->P[j].Cash = _Swap16bit(Data->P[j].Cash);
Data->P[j].Budget = _Swap16bit(Data->P[j].Budget);
Data->P[j].Prestige = _Swap16bit(Data->P[j].Prestige);
for (i = 0; i < 5; i++)
{
Data->P[j].PrestHist[i][0] =
_Swap16bit(Data->P[j].PrestHist[i][0]);
Data->P[j].PrestHist[1][1] =
_Swap16bit(Data->P[j].PrestHist[i][1]);
Data->P[j].PresRev[i] = _Swap16bit(Data->P[j].PresRev[i]);
Data->P[j].Spend[i][0] = _Swap16bit(Data->P[j].Spend[i][0]);
Data->P[j].Spend[i][1] = _Swap16bit(Data->P[j].Spend[i][1]);
Data->P[j].Spend[i][2] = _Swap16bit(Data->P[j].Spend[i][2]);
Data->P[j].Spend[i][3] = _Swap16bit(Data->P[j].Spend[i][3]);
}
Data->P[j].tempPrestige[0] = _Swap16bit(Data->P[j].tempPrestige[0]);
Data->P[j].tempPrestige[1] = _Swap16bit(Data->P[j].tempPrestige[1]);
for (i = 0; i < 40; i++)
{
Data->P[j].BudgetHistory[i] =
_Swap16bit(Data->P[j].BudgetHistory[i]);
Data->P[j].BudgetHistoryF[i] =
_Swap16bit(Data->P[j].BudgetHistoryF[i]);
}
for (i = 0; i < 65; i++)
{
Data->P[j].Pool[i].Prestige =
_Swap16bit(Data->P[j].Pool[i].Prestige);
}
Data->P[j].PastMis = _Swap16bit(Data->P[j].PastMis);
for (i = 0; i < 30; i++)
Data->P[j].PastIntel[i].num =
_Swap16bit(Data->P[j].PastIntel[i].num);
}
_SwapEquipment();
// End of GameDatSwap
}
void _SwapEquipment(void)
{
int plr = 0;
int i = 0;
for (plr = 0; plr < 2; ++plr)
{
for (i = 0; i < 3; i++)
{
Data->P[plr].Probe[i].InitCost =
_Swap16bit(Data->P[plr].Probe[i].InitCost);
Data->P[plr].Probe[i].UnitWeight =
_Swap16bit(Data->P[plr].Probe[i].UnitWeight);
Data->P[plr].Probe[i].MaxPay =
_Swap16bit(Data->P[plr].Probe[i].MaxPay);
Data->P[plr].Probe[i].Safety =
_Swap16bit(Data->P[plr].Probe[i].Safety);
}
for (i = 0; i < 5; i++)
{
Data->P[plr].Rocket[i].InitCost =
_Swap16bit(Data->P[plr].Rocket[i].InitCost);
Data->P[plr].Rocket[i].UnitWeight =
_Swap16bit(Data->P[plr].Rocket[i].UnitWeight);
Data->P[plr].Rocket[i].MaxPay =
_Swap16bit(Data->P[plr].Rocket[i].MaxPay);
Data->P[plr].Rocket[i].Safety =
_Swap16bit(Data->P[plr].Rocket[i].Safety);
}
for (i = 0; i < 7; i++)
{
Data->P[plr].Manned[i].InitCost =
_Swap16bit(Data->P[plr].Manned[i].InitCost);
Data->P[plr].Manned[i].UnitWeight =
_Swap16bit(Data->P[plr].Manned[i].UnitWeight);
Data->P[plr].Manned[i].MaxPay =
_Swap16bit(Data->P[plr].Manned[i].MaxPay);
Data->P[plr].Manned[i].Safety =
_Swap16bit(Data->P[plr].Manned[i].Safety);
}
for (i = 0; i < 7; i++)
{
Data->P[plr].Misc[i].InitCost =
_Swap16bit(Data->P[plr].Misc[i].InitCost);
Data->P[plr].Misc[i].UnitWeight =
_Swap16bit(Data->P[plr].Misc[i].UnitWeight);
Data->P[plr].Misc[i].MaxPay =
_Swap16bit(Data->P[plr].Misc[i].MaxPay);
Data->P[plr].Misc[i].Safety =
_Swap16bit(Data->P[plr].Misc[i].Safety);
}
}
}
void _SwapPatchHdr(PatchHdr* hdr)
{
assert(hdr);
hdr->w = _Swap16bit(hdr->w);
hdr->h = _Swap16bit(hdr->h);
hdr->size = _Swap16bit(hdr->size);
hdr->offset = _Swap32bit(hdr->offset);
}
void _SwapPatchHdrSmall(PatchHdrSmall* hdr)
{
assert(hdr);
hdr->size = _Swap16bit(hdr->size);
hdr->offset = _Swap32bit(hdr->offset);
}
/* vim: set noet ts=4 sw=4 tw=77: */