1
1
#include " global.h"
2
2
#include " memcard.h"
3
3
4
- #include < ttyd/msgdrv.h>
5
- #include < ttyd/memory.h>
6
- #include < ttyd/mario_pouch.h>
7
- #include < ttyd/mario.h>
8
- #include < ttyd/mario_motion.h>
9
- #include < ttyd/seq_mapchange.h>
10
-
11
4
#include < cstring>
12
5
13
6
namespace mod {
@@ -2223,246 +2216,4 @@ void setInitialSettings()
2223
2216
FrameCounter.ButtonCombo [RESET] = PAD_L | PAD_DPAD_RIGHT;
2224
2217
}
2225
2218
2226
- void SetCustomText::customTextInit (const char *initialText, uint32_t maxTextSize)
2227
- {
2228
- char *tempBuffer = reinterpret_cast <char *>(
2229
- clearMemory (Buffer, CUSTOM_TEXT_BUFFER_SIZE));
2230
-
2231
- if (initialText)
2232
- {
2233
- #ifdef TTYD_JP
2234
- // Custom text doesn't currently support Japanese characters
2235
- if (ttyd::msgdrv::_ismbblead (initialText[0 ]))
2236
- {
2237
- // Text starts with a Japanese character
2238
- CurrentIndex = 0 ;
2239
- }
2240
- else
2241
- {
2242
- #endif
2243
- uint32_t MaxIndex = maxTextSize - 1 ;
2244
- if (MaxIndex > (CUSTOM_TEXT_BUFFER_SIZE - 1 ))
2245
- {
2246
- MaxIndex = (CUSTOM_TEXT_BUFFER_SIZE - 1 );
2247
- }
2248
-
2249
- uint32_t Length = strlen (initialText);
2250
- if (Length > MaxIndex)
2251
- {
2252
- Length = MaxIndex;
2253
- }
2254
-
2255
- CurrentIndex = static_cast <uint8_t >(Length);
2256
- strncpy (tempBuffer, initialText, Length);
2257
- #ifdef TTYD_JP
2258
- }
2259
- #endif
2260
- }
2261
- else
2262
- {
2263
- CurrentIndex = 0 ;
2264
- }
2265
- }
2266
-
2267
- CustomStateStruct * ManageCustomStates::resizeStateMemory (
2268
- CustomStateStruct *state, uint32_t numEntries, int32_t incrementAmount)
2269
- {
2270
- uint32_t CurrentStatesSize = sizeof (CustomStateStruct) * numEntries;
2271
-
2272
- // Allocate temporary memory to hold the states
2273
- // Allocate the memory on the smart heap to avoid fragmentation
2274
- ttyd::memory::SmartAllocationData *SmartData =
2275
- allocFromSmartHeap (CurrentStatesSize,
2276
- ttyd::memory::SmartAllocationGroup::kNone );
2277
-
2278
- // Set up a temporary local variable to use for getting the memory
2279
- CustomStateStruct *tempStateSmart = reinterpret_cast <CustomStateStruct *>(SmartData->pMemory );
2280
-
2281
- // Copy the states from the old memory to the temporary memory
2282
- memcpy (tempStateSmart, state, CurrentStatesSize);
2283
-
2284
- // Free the old memory
2285
- delete[] (state);
2286
-
2287
- // Allocate new memory to hold the states
2288
- state = new CustomStateStruct[numEntries + incrementAmount];
2289
-
2290
- // Copy the states from the temporary memory to the new memory
2291
- memcpy (state, tempStateSmart, CurrentStatesSize);
2292
-
2293
- // Free the temporary memory
2294
- ttyd::memory::smartFree (SmartData);
2295
- return state;
2296
- }
2297
-
2298
- char *ManageCustomStates::createCustomState ()
2299
- {
2300
- uint32_t tempTotalEntries = TotalEntries;
2301
- CustomStateStruct *tempState = State;
2302
-
2303
- if (tempTotalEntries == 0 )
2304
- {
2305
- // No custom states exist, so create one
2306
- if (tempState)
2307
- {
2308
- delete[] (tempState);
2309
- }
2310
-
2311
- tempState = new CustomStateStruct;
2312
- State = tempState;
2313
-
2314
- tempTotalEntries = 1 ;
2315
- TotalEntries = tempTotalEntries;
2316
- }
2317
- else if (tempTotalEntries >= CUSTOM_STATES_MAX_COUNT)
2318
- {
2319
- // Maximum number of states have been made
2320
- return nullptr ;
2321
- }
2322
- else
2323
- {
2324
- tempState = resizeStateMemory (tempState, tempTotalEntries, 1 );
2325
- State = tempState;
2326
-
2327
- tempTotalEntries++;
2328
- TotalEntries = tempTotalEntries;
2329
- }
2330
-
2331
- // Set the info for the new state
2332
- tempState = &tempState[tempTotalEntries - 1 ];
2333
-
2334
- // Back up the inventory
2335
- uint32_t PouchPtr = reinterpret_cast <uint32_t >(ttyd::mario_pouch::pouchGetPtr ());
2336
-
2337
- // Standard items
2338
- memcpy (
2339
- tempState->StandardItems ,
2340
- reinterpret_cast <void *>(PouchPtr + 0x192 ),
2341
- sizeof (tempState->StandardItems ));
2342
-
2343
- // Important items
2344
- memcpy (
2345
- tempState->ImportantItems ,
2346
- reinterpret_cast <void *>(PouchPtr + 0xA0 ),
2347
- sizeof (tempState->ImportantItems ));
2348
-
2349
- // Badges
2350
- memcpy (
2351
- tempState->Badges ,
2352
- reinterpret_cast <void *>(PouchPtr + 0x1FA ),
2353
- sizeof (tempState->Badges ));
2354
-
2355
- // Equipped badges
2356
- memcpy (
2357
- tempState->EquippedBadges ,
2358
- reinterpret_cast <void *>(PouchPtr + 0x38A ),
2359
- sizeof (tempState->EquippedBadges ));
2360
-
2361
- // Stored items
2362
- memcpy (
2363
- tempState->StoredItems ,
2364
- reinterpret_cast <void *>(PouchPtr + 0x1BA ),
2365
- sizeof (tempState->StoredItems ));
2366
-
2367
- // Back up some of Mario's data
2368
- CustomStateMarioVars *MarioVars = &tempState->MarioVars ;
2369
- MarioVars->currentHP = *reinterpret_cast <int16_t *>(PouchPtr + 0x70 );
2370
- MarioVars->maxHP = *reinterpret_cast <int16_t *>(PouchPtr + 0x72 );
2371
- MarioVars->currentFP = *reinterpret_cast <int16_t *>(PouchPtr + 0x74 );
2372
- MarioVars->maxFP = *reinterpret_cast <int16_t *>(PouchPtr + 0x76 );
2373
- MarioVars->maxHPEnteringBattle = *reinterpret_cast <int16_t *>(PouchPtr + 0x8E );
2374
- MarioVars->maxFPEnteringBattle = *reinterpret_cast <int16_t *>(PouchPtr + 0x90 );
2375
- MarioVars->currentSP = *reinterpret_cast <int16_t *>(PouchPtr + 0x7A );
2376
- MarioVars->maxSP = *reinterpret_cast <int16_t *>(PouchPtr + 0x7C );
2377
- MarioVars->availableBP = *reinterpret_cast <int16_t *>(PouchPtr + 0x92 );
2378
- MarioVars->maxBP = *reinterpret_cast <int16_t *>(PouchPtr + 0x94 );
2379
- MarioVars->rank = *reinterpret_cast <int16_t *>(PouchPtr + 0x88 );
2380
- MarioVars->level = *reinterpret_cast <int16_t *>(PouchPtr + 0x8A );
2381
- MarioVars->starPowersObtained = *reinterpret_cast <uint16_t *>(PouchPtr + 0x8C );
2382
- MarioVars->starPoints = *reinterpret_cast <int16_t *>(PouchPtr + 0x96 );
2383
- MarioVars->coins = *reinterpret_cast <int16_t *>(PouchPtr + 0x78 );
2384
-
2385
- // Back up the partner data
2386
- memcpy (
2387
- tempState->PartyData ,
2388
- reinterpret_cast <void *>(PouchPtr + sizeof (ttyd::mario_pouch::PouchPartyData)),
2389
- sizeof (tempState->PartyData ));
2390
-
2391
- // Back up the sequence position
2392
- tempState->SequencePosition = getSequencePosition ();
2393
-
2394
- // Back up which partner is currently out
2395
- ttyd::mario::Player *player = ttyd::mario::marioGetPtr ();
2396
- uint32_t PartnerPtr = reinterpret_cast <uint32_t >(getPartnerPointer ());
2397
- if (PartnerPtr)
2398
- {
2399
- tempState->PartnerOut = player->prevFollowerId [0 ];
2400
- }
2401
-
2402
- // Back up which follower is currently out
2403
- uint32_t FollowerPtr = reinterpret_cast <uint32_t >(getFollowerPointer ());
2404
- if (FollowerPtr)
2405
- {
2406
- tempState->FollowerOut = player->prevFollowerId [1 ];
2407
- }
2408
-
2409
- // Back up if Mario is currently using Boat Mode or not
2410
- if (player->currentMotionId == ttyd::mario_motion::MarioMotions::kShip )
2411
- {
2412
- tempState->MarioIsShip = true ;
2413
- }
2414
- else
2415
- {
2416
- tempState->MarioIsShip = false ;
2417
- }
2418
-
2419
- // Back up the current map
2420
- strncpy (
2421
- tempState->CurrentMap ,
2422
- ttyd::seq_mapchange::NextMap,
2423
- sizeof (tempState->CurrentMap ));
2424
-
2425
- // Back up the current loading zone
2426
- strncpy (
2427
- tempState->CurrentBero ,
2428
- ttyd::seq_mapchange::NextBero,
2429
- sizeof (tempState->CurrentBero ));
2430
-
2431
- // Return a pointer to the new state's name
2432
- return tempState->StateName ;
2433
- }
2434
-
2435
- uint32_t ManageCustomStates::deleteCustomState (uint32_t stateIndex)
2436
- {
2437
- CustomStateStruct *tempState = State;
2438
- uint32_t tempTotalEntries = TotalEntries;
2439
-
2440
- // Decrement TotalEntries now since it'll be used several times in the following code
2441
- tempTotalEntries--;
2442
- TotalEntries = tempTotalEntries;
2443
-
2444
- // Check if there are other states left after deleting the selected one
2445
- if (tempTotalEntries > 0 )
2446
- {
2447
- // If deleting the last entry, don't do any moving beforehand
2448
- if (stateIndex < tempTotalEntries)
2449
- {
2450
- // Move all of the states under the one being deleted up by one slot
2451
- uint32_t CopySize = sizeof (CustomStateStruct) * (tempTotalEntries - stateIndex);
2452
- memcpy (&tempState[stateIndex], &tempState[stateIndex + 1 ], CopySize);
2453
- }
2454
-
2455
- State = resizeStateMemory (tempState, tempTotalEntries, 0 );
2456
- }
2457
- else
2458
- {
2459
- // There are no more states left
2460
- delete[] (tempState);
2461
- State = nullptr ;
2462
- }
2463
-
2464
- // Return the total number of entries
2465
- return tempTotalEntries;
2466
- }
2467
-
2468
2219
}
0 commit comments