66using RomUtilities ;
77using System . Collections ;
88using System . IO ;
9+ using System . Security . Cryptography ;
910
1011namespace FF1Lib
1112{
1213 // ReSharper disable once InconsistentNaming
1314 public partial class FF1Rom : NesRom
1415 {
15- public const string Version = "2.2.1 " ;
16+ public const string Version = "2.3.0 " ;
1617
1718 public const int RngOffset = 0x7F100 ;
1819 public const int RngSize = 256 ;
@@ -310,14 +311,22 @@ public void Randomize(Blob seed, Flags flags)
310311 }
311312
312313 var itemText = ReadText ( ItemTextPointerOffset , ItemTextPointerBase , ItemTextPointerCount ) ;
314+ // var dialogueText = ReadText(DialogueTextPointerOffset, DialogueTextPointerBase, DialogueTextPointerCount);
313315 FixVanillaRibbon ( itemText ) ;
314316 ExpGoldBoost ( flags . ExpBonus , flags . ExpMultiplier ) ;
315317 ScalePrices ( flags . PriceScaleFactor , flags . ExpMultiplier , flags . VanillaStartingGold , itemText , rng ) ;
316318
319+
320+ if ( flags . WarMECHMode != WarMECHMode . Vanilla )
321+ {
322+ WarMECHNpc ( flags . WarMECHMode , rng , maps ) ;
323+ }
324+
317325 overworldMap . ApplyMapEdits ( ) ;
318326 WriteMaps ( maps ) ;
319327
320328 WriteText ( itemText , ItemTextPointerOffset , ItemTextPointerBase , ItemTextOffset , UnusedGoldItems ) ;
329+ // WriteText(dialogueText, DialogueTextPointerOffset, DialogueTextPointerBase, DialogueTextOffset);
321330
322331 if ( flags . EnemyScaleFactor > 1 )
323332 {
@@ -334,6 +343,8 @@ public void Randomize(Blob seed, Flags flags)
334343 EnableCanalBridge ( ) ;
335344 }
336345
346+ SetProgressiveScaleMode ( flags . ProgressiveScaleMode ) ;
347+
337348 // We have to do "fun" stuff last because it alters the RNG state.
338349 RollCredits ( rng ) ;
339350
@@ -450,7 +461,7 @@ private void ExtraTrackingAndInitCode()
450461 PutInBank ( 0x0F , 0x8800 , Blob . FromHex ( "A000B186C902F005C908F00160A018B186301BC8B1863016C8B1863011C8B186300CA026B1861869010AA0209186A01CB186301AC8B1863015C8B1863010C8B186300BA026B186186901A022918660" ) ) ;
451462
452463 // Copyright overhaul, see 0F_8960_DrawSeedAndFlags.asm
453- PutInBank ( 0x0F , 0x8960 , Blob . FromHex ( "A9238D0620A9208D0620A200BD00898D0720E8E060D0F560 " ) ) ;
464+ PutInBank ( 0x0F , 0x8980 , Blob . FromHex ( "A9238D0620A9208D0620A200BD00898D0720E8E080D0F560 " ) ) ;
454465
455466 // Fast Battle Boxes
456467 PutInBank ( 0x0F , 0x8A00 , Blob . FromHex ( "A940858AA922858BA91E8588A969858960" ) ) ;
@@ -467,6 +478,13 @@ private void ExtraTrackingAndInitCode()
467478 // Change INT to MDEF in the Status screen
468479 Put ( 0x388F5 , Blob . FromHex ( "968D8E8F" ) ) ;
469480 Data [ 0x38DED ] = 0x25 ;
481+
482+ //Key Items + Progressive Scaling
483+ PutInBank ( 0x0F , 0x9000 , Blob . FromHex ( "A200AD2160F001E8AD2260F001E8AD2560F001E8AD2A60F001E8AD2B60F001E8AD2C60F001E8AD2E60F001E8AD3060F001E8AD0060F001E8AD1260F001E8AD0460F001E8AD0860F001E8AD0C60D001E8AD2360D007AD0A622902F001E8AD2460D007AD05622902F001E8AD2660D007AD08622902F001E8AD2760D007AD09622902F001E8AD2860D007AD0B622902F001E8AD2960D007AD14622901D001E8AD2D60D007AD0E622902F001E8AD2F60D007AD13622903F001E88EB86060" ) ) ;
484+ PutInBank ( 0x1F , 0xCFCB , CreateLongJumpTableEntry ( 0x0F , 0x9100 ) ) ;
485+ //Division routine
486+ PutInBank ( 0x0F , 0x90C0 , Blob . FromHex ( "8A48A9008513A210261026112613A513C5129004E512851326102611CAD0EDA513851268AA60" ) ) ;
487+ // Progressive scaling also writes to 0x9100 approaching 200 bytes, begin next Put at 0x9200.
470488 }
471489
472490 public void MakeSpaceIn1F ( )
@@ -517,15 +535,35 @@ public void WriteSeedAndFlags(string version, string seed, string flags)
517535 Put ( 0x38486 , Blob . FromHex ( "20FCFE60" ) ) ;
518536
519537 // DrawSeedAndFlags LongJump
520- PutInBank ( 0x1F , 0xFEFC , CreateLongJumpTableEntry ( 0x0F , 0x8960 ) ) ;
538+ PutInBank ( 0x1F , 0xFEFC , CreateLongJumpTableEntry ( 0x0F , 0x8980 ) ) ;
521539
522- // Put the new string data in a known location.
523- PutInBank ( 0x0F , 0x8900 , Blob . Concat ( new Blob [ ]
540+ var sha = File . Exists ( "version.txt" ) ? File . ReadAllText ( "version.txt" ) . Trim ( ) : "development" ;
541+ Blob hash ;
542+ if ( sha == "development" )
543+ {
544+ hash = FF1Text . TextToCopyrightLine ( "DEVELOPMENT VERSION" ) ;
545+ }
546+ else
524547 {
548+ var hasher = SHA256 . Create ( ) ;
549+ hash = hasher . ComputeHash ( Encoding . ASCII . GetBytes ( $ "{ seed } _{ flags } _{ sha } ") ) ;
550+
551+ var hashpart = BitConverter . ToUInt64 ( hash , 0 ) ;
552+ hash = Blob . FromHex ( "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" ) ;
553+ for ( int i = 13 ; i < 19 ; i ++ )
554+ {
555+ // 0xD4 through 0xDF are good symbols to use.
556+ hash [ i ] = ( byte ) ( 0xD4 + hashpart % 12 ) ;
557+ hashpart /= 12 ;
558+ }
559+ }
560+
561+ // Put the new string data in a known location.
562+ PutInBank ( 0x0F , 0x8900 , Blob . Concat (
525563 FF1Text . TextToCopyrightLine ( "Final Fantasy Randomizer " + version ) ,
526564 FF1Text . TextToCopyrightLine ( "Seed " + seed ) ,
527565 FF1Text . TextToCopyrightLine ( flags ) ,
528- } ) ) ;
566+ hash ) ) ;
529567 }
530568
531569 public void ShuffleRng ( MT19337 rng )
0 commit comments