Skip to content

Commit

Permalink
Merge pull request #112 from Fenyx4/avatar-0-3-0
Browse files Browse the repository at this point in the history
Avatar 0 3 0
  • Loading branch information
Fenyx4 authored Jul 29, 2021
2 parents a0ef111 + 56d459a commit 584a526
Show file tree
Hide file tree
Showing 24 changed files with 635 additions and 291 deletions.
63 changes: 41 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,45 @@ Requires Ultima IV which is available for free at https://www.gog.com/game/ultim

```
Options:
-s |--s <seed> The seed for the randomizer. Same seed will produce the same map. Defaults to random value.
-p |--p <path> Path to Ultima 4 installation. Leaving blank will assume it is the working directory.
-r |--r Restore original Ultima 4 files.
--miniMap Output a minimap of the overworld.
-o |--overworld Sets randomization level for Overworld map. 1 for no change. 2 for shuffle overworld locations. 5 for randomize the entire map. Defaults to 5.
--spellRemove Put in the letters of the spells you want removed. e.g. "--spellRemove zed" would remove zdown, energy field and dispel.
--mixQuantity Lets you input how much of a spell you want to mix.
--dngStone Randomize the location of stones in the dungeons
--fixes Collection of non-gameplay fixes.
--hythlothFix Fixes an issue with Hythloth dungeon room.
--sleepLockAssist Helps prevent sleeplock in battles.
--activePlayer Allow selecting which characters are active in combat.
--appleHitChance Change hit chance to behave like the original Apple II version.
--diagonalAttack Allow diagonal attacks in combat.
--sacrificeFix Adds a way to gain sacrifice which the shrine says should work.
--questItems Percentage chance to start with a quest item.
--runes Randomize the location of the runes.
--karmaValue Value to override starting karma value for a virtue. Leave blank for random.
--karmaPercentage Percentage chance to override a starting karma value for a virtue. Default 0 (no override).
--spoilerLog Output a spoiler log.
-? | -h | --help Show help information
-s |--s <seed> The seed for the randomizer. Same seed will produce the same map. Defaults to random value.
-p |--p <path> Path to Ultima 4 installation. Leaving blank will assume it is the working directory.
-r |--r Restore original Ultima 4 files.
-e |--encoded Encoded flags. Overrides all other flags.
--miniMap Output a minimap of the overworld.
-o |--overworld Sets randomization level for Overworld map. 1 for no change. 2 for shuffle overworld locations. 5 for randomize the entire map. Defaults to 5.
--spellRemove Put in the letters of the spells you want removed. e.g. "--spellRemove zed" would remove zdown, energy field and dispel.
--startingWeaponsArmor Randomize the weapons and armor player and companions start with.
--mixQuantity Lets you input how much of a spell you want to mix.
--dngStone Randomize the location of stones in the dungeons
--fixes Collection of non-gameplay fixes.
--hythlothFix Fixes an issue with Hythloth dungeon room.
--sleepLockAssist Helps prevent sleeplock in battles.
--activePlayer Allow selecting which characters are active in combat.
--appleHitChance Change hit chance to behave like the original Apple II version.
--diagonalAttack Allow diagonal attacks in combat.
--sacrificeFix Adds a way to gain sacrifice which the shrine says should work.
--runes Randomize the location of the runes.
--mantras Randomize the mantras.
--wordOfPassage Randomize the Word of Passage.
--questItems <0-100> Percentage chance to start with a quest item.
--karmaValue <value> Value to override starting karma value for a virtue. Leave blank for random.
--karmaPercentage <0-100> Percentage chance to override a starting karma value for a virtue. Default 0 (no override).
--monsterDamage <0-3> Value to change how much damage monsters do. Allowed values 0-3. 0 is quad damage. 1 is more damge. 2 is default. 3 is less damage.
--weaponDamage <1-3> Value to change how much damage weapons do. Allowed values 1-3. 1 is more damge. 2 is default. 3 is less damage.
--earlierMonsters Make more difficult monsters appear earlier.
--monsterQty More monsters from the start.
--noRequireFullParty Don't require the full party.
--randomizeSpells Randomizes the gate and resurrection spells that you learn in game.
--sextant Start with a sextant.
--clothMap Cloth map of the world.
--principleItems Randomize the order of the Principle Items.
--townSaves Enable saving in towns.
--daemonTrigger Fix daemon spawn in Abyss
--awakenUpgrade Awaken spell awakens all characters.
--shopOverflow Don't allow overflow exploit in shops.
--vgaPatch VGA patch compatibility. Run randomizer after applying VGA patch.
--spoilerLog Output a spoiler log.
-? | -h | --help Show help information
```

All the files the randomizer changes get backed up with the extension ".orig" added. Run with '-r' to restore to the original game.
Expand All @@ -40,7 +58,8 @@ Example: https://imgur.com/qNRxpSy

## Helping

If you end up making changes to the game's source code you will need to update the diff files. Run U4DosRandomizer.Patcher with the below parameters then copy the diffs into U4DosRandomizer/patches and rebuild.
```-b "E:\Projects\U4DosRandomizer\u4_decompile\SRC\ORIGINAL\AVATAR.EXE" -s "E:\Projects\U4DosRandomizer\u4_decompile\SRC\ORIGINAL\AVATAR.EXE.sig" -n "E:\Projects\U4DosRandomizer\u4_decompile\SRC\ORIGINAL\U4_MAIN.EXE" -d "E:\Projects\U4DosRandomizer\u4_decompile\SRC\ORIGINAL\AVATAR.EXE.octodiff"```
```-b "E:\Projects\U4DosRandomizer\u4_decompile\SRC-TITLE\ORIGINAL\TITLE.EXE.orig" -s "E:\Projects\U4DosRandomizer\u4_decompile\SRC-TITLE\ORIGINAL\TITLE.EXE.sig" -n "E:\Projects\U4DosRandomizer\u4_decompile\SRC-TITLE\ORIGINAL\TITLE_0.EXE" -d "E:\Projects\U4DosRandomizer\u4_decompile\SRC-TITLE\ORIGINAL\TITLE.EXE.octodiff"```

"The generation of random numbers is too important to be left to chance." - Robert R. Coveyou
"The generation of random numbers is too important to be left to chance." - Robert R. Coveyou
42 changes: 42 additions & 0 deletions U4DosRandomizer/Avatar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ public void Load(string path, UltimaData data, IWorldMap worldMap, Flags flags)
textOffset++;
}

data.PrincipleItemRequirements.Add(BitConverter.ToUInt16(avatarBytes, AvatarOffset.BELL_REQUIREMENT_OFFSET-1));
data.PrincipleItemRequirements.Add(BitConverter.ToUInt16(avatarBytes, AvatarOffset.BOOK_REQUIREMENT_OFFSET-1));
data.PrincipleItemRequirements.Add(BitConverter.ToUInt16(avatarBytes, AvatarOffset.CANDLE_REQUIREMENT_OFFSET-1));

var wordOfPassageTextBytes = new List<byte>();

for (int offSet = 0; offSet < 9; offSet++)
Expand Down Expand Up @@ -433,6 +437,14 @@ public void Update(UltimaData data, Flags flags)
}
}

if (data.PrincipleItemRequirements[0] != 1024)
{
avatarBytes.OverwriteBytes((ushort)data.PrincipleItemRequirements[0], AvatarOffset.BELL_REQUIREMENT_OFFSET-1);
avatarBytes.OverwriteBytes((ushort)data.PrincipleItemRequirements[1], AvatarOffset.BOOK_REQUIREMENT_OFFSET-1);
avatarBytes.OverwriteBytes((ushort)data.PrincipleItemRequirements[2], AvatarOffset.CANDLE_REQUIREMENT_OFFSET-1);
avatarBytes[AvatarOffset.ENABLE_PRINCIPLE_ITEM_REORDER_OFFSET] = (byte)0x0;
}

var wordOfPassageBytes = Encoding.ASCII.GetBytes(data.WordOfPassage.ToLower());
for (int j = 0; j < wordOfPassageBytes.Length; j++)
{
Expand Down Expand Up @@ -625,6 +637,36 @@ public void Update(UltimaData data, Flags flags)
avatarBytes[AvatarOffset.LB_PARTY_COMPARISON] = 0x00;
}

if (flags.TownSaves)
{
avatarBytes[AvatarOffset.ENABLE_TOWN_SAVE1] = (byte)0x0;
avatarBytes[AvatarOffset.ENABLE_TOWN_SAVE2] = (byte)0x0;
avatarBytes[AvatarOffset.ENABLE_TOWN_SAVE3] = (byte)0x0;
avatarBytes[AvatarOffset.ENABLE_TOWN_SAVE4] = (byte)0x0;
}

if (flags.DaemonTrigger)
{
avatarBytes[AvatarOffset.ENABLE_DAEMON_TRIGGER_FIX] = (byte)0x0;
}

if (flags.Fixes)
{
avatarBytes[AvatarOffset.ENABLE_MAP_EDGE_FIX1] = (byte)0x0;
avatarBytes[AvatarOffset.ENABLE_MAP_EDGE_FIX2] = (byte)0x0;
avatarBytes[AvatarOffset.ENABLE_MAP_EDGE_FIX3] = (byte)0x0;
}

if (flags.AwakenUpgrade)
{
avatarBytes[AvatarOffset.ENABLE_AWAKEN_ALL] = (byte)0x0;
}

if (flags.ShopOverflowFix)
{
avatarBytes[AvatarOffset.ENABLE_WEAPON_OVERFLOW_FIX] = (byte)0x0;
}

if (flags.VGAPatch)
{
ApplyVGAPatch();
Expand Down
Loading

0 comments on commit 584a526

Please sign in to comment.