-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWSFModV1.cpp
More file actions
577 lines (475 loc) · 12.5 KB
/
Copy pathWSFModV1.cpp
File metadata and controls
577 lines (475 loc) · 12.5 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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
/*
Whelchel Sound Format
Based on MODs
Josh Whelchel 2003
www.syntesis.ath.cx
*/
/***************************************************************************
* Copyright (C) 2005 by Josh Whelchel *
* joshwhel@insightbb.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
///
/// \file WSFMod.cpp Main MOD functions
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "WSFGlob.h"
#include "WSFComp.h"
#include "WSFPackV1.h"
#include "WSFModV1.h"
#ifdef WINWSF
/*
WINWSF is a decleration used when compiling WinWSFTool.
This allows us to give detailed status reports through
the CStatusDlg class.
*/
#include "WinWSFTool\resource.h" // main symbols
#include "WinWSFTool\StdAfx.h"
#include "WinWSFTool\StatusDlg.h"
extern CStatusDlg *g_mStatus;
#endif
//////////////////////////////////////////////////////
// FreeGSPData()
//
// Author:
/// \author Josh Whelchel
/// \date 2/23/2003 1:07:03 AM
/// \param *gspData Pointer to free
/// \brief Frees a wsf_gspdata structure
///
//
//////////////////////////////////////////////////////
void FreeGSPData( wsf_gspdata *gspData );
//////////////////////////////////////////////////////
// InitGSPData()
//
// Author:
/// \author Josh Whelchel
/// \date 2/23/2003 1:17:37 AM
/// \param *gspData
/// \brief Inits wsf_gspdata struct.
/// nSamples must be filled first
///
//
//////////////////////////////////////////////////////
void InitGSPData( wsf_gspdata *gspData );
//////////////////////////////////////////////////////
// PushIntoGSP()
//
// Author:
/// \author Josh Whelchel
/// \date 2/23/2003 7:32:36 PM
/// \param *gspData GSP Data
/// \param nSize Size of Sample
/// \param nOffset Offset of Sample
/// \param nSamps Samples
/// \param nCh Channels
/// \param nBit Bitrate
//
//////////////////////////////////////////////////////
void PushIntoGSP( wsf_gspdata *gspData, wsul nSize, wsul nOffset, wsul nSamps, wsfb nCh, wsfb nBit, char *cName );
//***************************************************************************** */
// GetModType()
//
// Purpose: Gets MOD Type
//
// Author : [Josh Whelchel], Created : [2/12/2003 11:27:52 AM]
// Parameters:
//
// [*cFile] :
//
// Returns: int
//
//***************************************************************************** */
int GetModType( char *cFile );
//*****************************************************************************
// SearchForString()
//
// Purpose: Searches buffer for a string
//
// Author : [Josh Whelchel], Created : [2/9/2003 1:58:21 PM]
// Parameters:
//
// [*lpBuf] :
// [nSize] :
// [*cStr] :
//
// Returns: UL
//
//*****************************************************************************
wsfb *SearchForString( wsfb *lpBuf, wsul nSize, char *cStr, int nTagLen );
//////////////////////////////////////////////////////
// *GetBaseLoader()
//
// Author:
/// \author Josh Whelchel
/// \date 2/22/2003 6:07:14 PM
/// \param nModType Mod Type from WSFModVers enum
/// \return
/// \brief Returns CBaseLoader of mod type
///
//
//////////////////////////////////////////////////////
CBaseLoader *GetBaseLoader( wsfb nModType );
//***************************************************************************** */
// CWSFModV1::CWSFModV1()
//
// Purpose: Construct
//
// Author : [Josh Whelchel], Created : [2/12/2003 11:17:41 AM]
// Parameters:
//
//
// Returns: none
//
//***************************************************************************** */
CWSFModV1::CWSFModV1()
{
// Allocate new memories and stuff, and set loaded to 0
m_nLoaded = 0;
m_nModType = WSFM_NONE;
m_fPack = NULL;
m_wPack = new CWSFPackV1;
memset(&m_wLD,0,sizeof(m_wLD));
m_cModTitle[0] = 0;
}
//***************************************************************************** */
// CWSFModV1::~CWSFModV1()
//
// Purpose: Killer
//
// Author : [Josh Whelchel], Created : [2/12/2003 11:18:43 AM]
// Parameters:
//
//
// Returns: none
//
//***************************************************************************** */
CWSFModV1::~CWSFModV1()
{
if (m_nLoaded)
FreeMod(); // Free mod if loaded
delete m_wPack;
}
//***************************************************************************** */
// CWSFModV1::SetPackName()
//
// Purpose: Sets Pack NAme
//
// Author : [Josh Whelchel], Created : [2/15/2003 4:55:51 PM]
// Parameters:
//
// [*cName] :
//
// Returns: int
//
//***************************************************************************** */
int CWSFModV1::SetPackName( char *cName )
{
strncpy(m_cCurPack,cName,26);
m_cCurPack[26] = 0;
return 0;
}
//***************************************************************************** */
// CWSFModV1::LoadPack()
//
// Purpose: Loads Pack
//
// Author : [Josh Whelchel], Created : [2/15/2003 5:04:03 PM]
// Parameters:
//
// [*cName] :
//
// Returns: int
//
//***************************************************************************** */
int CWSFModV1::LoadPack( char *cName )
{
strncpy(m_cCurPack,cName,26);
m_cCurPack[26] = 0;
m_wPack->LoadPack(cName,NULL,0);
return 0;
}
//***************************************************************************** */
// CWSFModV1::SavePack()
//
// Purpose: Saves Pack
//
// Author : [Josh Whelchel], Created : [2/16/2003 10:53:06 AM]
// Parameters:
//
// [void] :
//
// Returns: int
//
//***************************************************************************** */
int CWSFModV1::SavePack( int nComp )
{
return m_wPack->SavePack(m_cCurPack,(wsfb)nComp);
}
//////////////////////////////////////////////////////
// CWSFModV1::ReplaceSamplesForSave()
//
// Author:
/// \author Josh Whelchel
/// \date 2/23/2003 5:37:08 PM
/// \param *wOut MOD Out Buffer
/// \param xBL Loader
/// \brief Prepares MOD Data buffer for save
///
//
//////////////////////////////////////////////////////
int CWSFModV1::ReplaceSamplesForSave( wsf_modout *wOut, CBaseLoader *xBL, wsf_loaddata *wLD )
{
wsul nSize;
wsfb *bDat;
wsul i;
wsul *nOffs;
int nSub;
// Copy over MOD Data
nSize = wLD->nModSize;
bDat = (wsfb*)malloc(nSize);
memcpy(bDat,wLD->bModData,nSize);
nSub = 0;
if (wLD->nSampleOffsets[0] == 0)
{
wsf_gspdata gD;
xBL->GetSamplePointers(bDat,nSize,&gD);
nOffs = (wsul*)malloc(sizeof(wsul)*wLD->nSamples);
memcpy(nOffs,gD.nSampOffs,sizeof(wsul)*wLD->nSamples);
FreeGSPData(&gD);
}
else
nOffs = wLD->nSampleOffsets;
// Mess with MOD Data until we have the samples refilled
for (i=0;i<wLD->nSamples;i++)
{
wsfb *bNew;
wsul nNew;
wsul nSOff;
// Get Offset
nSOff = nOffs[i];
// Replace Data
if (wLD->bSamples[i].nSize > 1)
{
bNew = xBL->ReplaceData(bDat,nSize,&nNew,nSOff,4,wLD->bSamples[i].bSampData,wLD->bSamples[i].nSize);
free(bDat);
bDat = bNew;
nSize = nNew;
nSub += 4-wLD->bSamples[i].nSize;
}
}
if (wLD->nSampleOffsets != nOffs)
free(nOffs);
wOut->bModData = bDat;
wOut->nSize = nSize;
return 0;
}
//***************************************************************************** */
// CWSFModV1::WriteMod()
//
// Purpose: Saves mod
//
// Author : [Josh Whelchel], Created : [2/12/2003 1:08:36 PM]
// Parameters:
//
// [*wOut] :
// [nWSF] : Save as WSF if true, otherwise use Mod Type
//
// Returns: int
//
//***************************************************************************** */
int CWSFModV1::WriteMod( wsf_modout *wOut, int nWSF, int *nSCounts )
{
int nr;
CBaseLoader *xBL;
// Calculate size :x
wOut->bModData = (wsfb*)malloc(0);
wOut->nSize = 0;
if (nWSF){
xBL = (CBaseLoader*)new CWSFLoaderV1;
((CWSFLoaderV1*)xBL)->SetPack(m_cCurPack,m_wPack);
// ((CWSFLoaderV1*)xBL)->SetPack(m_fPack);
#ifdef WINWSF
g_mStatus->SetSubProgressSteps((2+m_wPack->GetNumSamples())*m_wLD.nSamples);
#endif
nr = ((CWSFLoaderV1*)xBL)->Save(wOut,&m_wLD,nSCounts);
delete xBL;
}
else
{
xBL = GetBaseLoader(m_nModType);
if (!xBL)
return 1;
// Do Replace Samples HERE
ReplaceSamplesForSave(wOut,xBL,&m_wLD);
// Save
nr = xBL->Save(wOut,&m_wLD);
delete xBL;
}
return nr;
}
//***************************************************************************** */
// CWSFModV1::LoadMod()
//
// Purpose: Loads Mod
//
// Author : [Josh Whelchel], Created : [2/12/2003 11:23:11 AM]
// Parameters:
//
// [*cFileName] :
//
// Returns: int
//
//***************************************************************************** */
int CWSFModV1::LoadMod( char *cFileName, int nFreePack, wsul *nOSamps )
{
wsf_file *wf;
int nR;
wf = wsfopenfile(cFileName);
if (!wf)
return 1;
nR = LoadMod(wf,nFreePack,nOSamps,GetModType(cFileName));
wsfclose(wf);
return nR;
}
int CWSFModV1::LoadMod( wsfb *bData, wsul nSize, int nFreePack, wsul *nOSamps, int nType )
{
wsf_file *wf;
int nR;
wf = wsfopenmem(bData,nSize);
if (!wf)
return 1;
nR = LoadMod(wf,nFreePack,nOSamps,nType);
wsfclose(wf);
return nR;
}
int CWSFModV1::LoadMod( wsf_file *wf, int nFreePack, wsul *nOSamps, int nType )
{
int nR;
CBaseLoader *xBL;
wsfb *bMD;
wsul nMD;
FreeMod();
if (nOSamps)
nOSamps[0] = 666; /// 666 = Number could not be retrieved :/
// Get Mod Type
m_wLD.nModType = nType;
if (m_wLD.nModType == WSFM_WTF) // Interchangeable format
m_wLD.nModType = WSFM_WSF; // Set to WSF
// Mod not found
if (m_wLD.nModType == WSFM_NONE)
return 1;
m_nModType = m_wLD.nModType;
nMD = wf->nSize;
bMD = (wsfb*)malloc(nMD);
wsfread(bMD,nMD,wf);
nR = 1;
xBL = NULL;
xBL = GetBaseLoader(m_wLD.nModType);
if (xBL)
{
if (wf->cF)
xBL->SetFileName(wf->cF);
else
xBL->SetFileName("");
if (m_wLD.nModType == WSFM_WSF){
((CWSFLoaderV1*)xBL)->SetPack(m_cCurPack,m_wPack);
((CWSFLoaderV1*)xBL)->SetPack(m_fPack);
((CWSFLoaderV1*)xBL)->SetFreePack(nFreePack);
}
nR = xBL->Load(bMD,nMD,&m_wLD);
delete xBL;
}
free(bMD);
strcpy(m_cModTitle,m_wLD.cTitle);
m_nModType = m_wLD.nModType;
if (nOSamps)
nOSamps[0] = m_wLD.nSamples;
if (nR == 0)
m_nLoaded = 1;
return nR;
}
//////////////////////////////////////////////////////
// CWSFModV1::SetPassSum()
//
// Author:
/// \author Josh Whelchel
/// \date 4/5/2003 11:07:38 AM
/// \param nPassSum Password Sum
//
//////////////////////////////////////////////////////
void CWSFModV1::SetPassSum( int nPassSum )
{
m_wPack->SetPassSum(nPassSum);
}
//***************************************************************************** */
// CWSFModV1::FreeMod()
//
// Purpose: Frees Mod
//
// Author : [Josh Whelchel], Created : [2/15/2003 4:53:43 PM]
// Parameters:
//
// [void] :
//
// Returns: int
//
//***************************************************************************** */
int CWSFModV1::FreeMod( void )
{
unsigned int i;
if (!m_nLoaded)
return 1;
if (m_wLD.bSamples)
{
for (i=0;i<m_wLD.nSamples;i++){
if (m_wLD.bSamples[i].bSampData)
free(m_wLD.bSamples[i].bSampData); // Free only if we need to!
}
}
if (m_wLD.bModData)
free(m_wLD.bModData);
if (m_wLD.bSamples)
free(m_wLD.bSamples);
if (m_wLD.nSampleSizes)
free(m_wLD.nSampleSizes);
memset(&m_wLD,0,sizeof(m_wLD));
m_nLoaded = 0;
m_nModType = 0;
return 0;
}
//***************************************************************************** */
// CWSFModV1::FreePack()
//
// Purpose: Frees the pack
//
// Author : [Josh Whelchel], Created : [2/16/2003 12:12:55 PM]
// Parameters:
//
// [void] :
//
// Returns: int
//
//***************************************************************************** */
int CWSFModV1::FreePack( void )
{
m_cCurPack[0] = 0;
return m_wPack->FreePack();
}