Skip to content

Commit

Permalink
1.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
IngoHHacks committed Jun 5, 2023
1 parent e4caa45 commit e882a2b
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 44 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### GV 1.58:

## Release 1.3.3
- Improved character importing logic.

## Release 1.3.2
- Added support for pyro and weapon positioning in custom arenas.
- Added titantron camera auto-rotation.
Expand Down
41 changes: 22 additions & 19 deletions Patches/SaveFilePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,15 @@ public static void GameSaveFile_HCKKGEAPBMK_POST(int BHCMGLCHEGO)
SaveRemapper.PatchCustomContent(ref GameSaveFile.IOKDNAOAENK);
foreach (BetterCharacterDataFile file in ImportedCharacters)
{
Plugin.Log.LogInfo($"Importing character {file.CharacterData.name} with id {file.CharacterData.id}.");
Plugin.Log.LogInfo($"Importing character {file.CharacterData.name ?? "null"} with id {file.CharacterData.id.ToString() ?? "null"}");
string nameWithGuid = file._guid;
string overrideMode = file.OverrideMode + file.FindMode;
Character importedCharacter =
file.CharacterData.ToRegularCharacter(GameSaveFile.IOKDNAOAENK.savedChars);

string overrideMode = file.OverrideMode + "-" + file.FindMode;
Character importedCharacter = null;
if (!overrideMode.Contains("merge"))
{
importedCharacter = file.CharacterData.ToRegularCharacter(GameSaveFile.IOKDNAOAENK.savedChars);
}

bool previouslyImported = CheckIfPreviouslyImported(nameWithGuid);

overrideMode = overrideMode.ToLower();
Expand Down Expand Up @@ -235,10 +238,10 @@ public static void GameSaveFile_HCKKGEAPBMK_POST(int BHCMGLCHEGO)
case "merge-id":
case "merge-name":
case "merge-name_then_id":
int id3 = (overrideMode.Contains("id") ? importedCharacter.id : -1);
int id3 = (overrideMode.Contains("id") ? (file.CharacterData.id ?? -1) : -1);
if (overrideMode.Contains("name"))
{
var find = file.FindName ?? importedCharacter.name;
var find = file.FindName ?? file.CharacterData.name ?? throw new Exception($"No name found for file {nameWithGuid}");
try
{

Expand All @@ -251,38 +254,38 @@ public static void GameSaveFile_HCKKGEAPBMK_POST(int BHCMGLCHEGO)
}
if (id3 == -1)
{
Plugin.Log.LogError($"Could not find character with id {importedCharacter.id} and name {importedCharacter.name} using override mode {overrideMode}. Skipping.");
Plugin.Log.LogError($"Could not find character with id {file.CharacterData.id?.ToString() ?? "null"} and name {file.CharacterData.name ?? "null"} using override mode {overrideMode}. Skipping.");
break;
}
Character oldCharacter2 = GameSaveFile.IOKDNAOAENK.savedChars[id3];
file.CharacterData.MergeIntoCharacter(oldCharacter2);

GameSaveFile.IOKDNAOAENK.savedChars[id3] = oldCharacter2;
if (importedCharacter.fed != oldCharacter2.fed)
if (file.CharacterData.fed != null && file.CharacterData.fed.Value != oldCharacter2.fed)
{
if (GameSaveFile.IOKDNAOAENK.savedFeds[importedCharacter.fed].size + 1 ==
GameSaveFile.IOKDNAOAENK.savedFeds[importedCharacter.fed].roster.Length)
if (GameSaveFile.IOKDNAOAENK.savedFeds[file.CharacterData.fed.Value].size + 1 ==
GameSaveFile.IOKDNAOAENK.savedFeds[file.CharacterData.fed.Value].roster.Length)
{
Array.Resize(ref GameSaveFile.IOKDNAOAENK.savedFeds[importedCharacter.fed].roster,
GameSaveFile.IOKDNAOAENK.savedFeds[importedCharacter.fed].size + 2);
if (GameSaveFile.IOKDNAOAENK.savedFeds[importedCharacter.fed].roster.Length >
Array.Resize(ref GameSaveFile.IOKDNAOAENK.savedFeds[file.CharacterData.fed.Value].roster,
GameSaveFile.IOKDNAOAENK.savedFeds[file.CharacterData.fed.Value].size + 2);
if (GameSaveFile.IOKDNAOAENK.savedFeds[file.CharacterData.fed.Value].roster.Length >
Characters.fedLimit)
{
Characters.fedLimit++;
}
}

GameSaveFile.IOKDNAOAENK.savedFeds[importedCharacter.fed].size++;
GameSaveFile.IOKDNAOAENK.savedFeds[importedCharacter.fed]
.roster[GameSaveFile.IOKDNAOAENK.savedFeds[importedCharacter.fed].size] = id3;
GameSaveFile.IOKDNAOAENK.savedFeds[file.CharacterData.fed.Value].size++;
GameSaveFile.IOKDNAOAENK.savedFeds[file.CharacterData.fed.Value]
.roster[GameSaveFile.IOKDNAOAENK.savedFeds[file.CharacterData.fed.Value].size] = id3;
GameSaveFile.IOKDNAOAENK.savedFeds[oldCharacter2.fed].JHDJHBMIEOG(id3);
}

Plugin.Log.LogInfo(
$"Imported character with id {id3} and name {importedCharacter.name}, merging with existing character: {oldCharacter2.name}.");
$"Imported character with id {id3} and name {file.CharacterData.name ?? "null"}, merging with existing character: {oldCharacter2.name}.");
break;
}
ContentMappings.ContentMap.AddPreviouslyImportedCharacter(nameWithGuid, importedCharacter.id);
ContentMappings.ContentMap.AddPreviouslyImportedCharacter(nameWithGuid, importedCharacter?.id ?? file.CharacterData.id ?? -1);
}

GameSaveFile.IOKDNAOAENK.NCOHBLMFLLN(BHCMGLCHEGO);
Expand Down
9 changes: 5 additions & 4 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Plugin : BaseUnityPlugin
{
public const string PluginGuid = "IngoH.WrestlingEmpire.WECCL";
public const string PluginName = "Wrestling Empire Custom Content Loader";
public const string PluginVer = "1.3.2";
public const string PluginVer = "1.3.3";


internal static List<DirectoryInfo> AllModsImportDirs = new();
Expand Down Expand Up @@ -78,8 +78,8 @@ public class Plugin : BaseUnityPlugin
public const float PluginCharacterVersion = 1.56f;
public const float PluginVersion = 1.58f;

public const bool PreRelease = true;
public static string[] PreReleaseReasons = { "GameUpdate" };
public const bool PreRelease = false;
public static string[] PreReleaseReasons = { };

public static string[] EasterEggs =
{
Expand Down Expand Up @@ -933,7 +933,8 @@ internal static void ImportCharacters(DirectoryInfo dir)
int cur = 0;
foreach (FileInfo file in files)
{
BetterCharacterDataFile character = JsonConvert.DeserializeObject<BetterCharacterDataFile>(File.ReadAllText(file.FullName));
var json = File.ReadAllText(file.FullName);
BetterCharacterDataFile character = JsonConvert.DeserializeObject<BetterCharacterDataFile>(json);
if (character == null)
{
Log.LogError($"Failed to import character from {file.FullName}.");
Expand Down
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,18 @@ Characters are automatically exported to `./BepInEx/plugins/Export` when the gam

## Importing Characters

Characters can be imported by placing a JSON file inside `./BepInEx/plugins/Import`. Make sure to set
the `overrideMode` property to the desired mode.
`append` will add the imported character.
`override` will override the character with the same `id`.
`merge` will replace all non-default values of the character referenced by the `id`.
Imported JSON files will be automatically deleted after the game is saved (unless the config
option `DeleteImportedCharacters` is set to `false`).
Characters can be imported by placing a JSON file inside `./BepInEx/plugins/Import` with the `.character` extension.
The JSON file must contain a single object with:
`characterData`: The character data to import. Typically obtained by exporting a character.
Optional properties:
`overrideMode`: `append`, `override`, or `merge`.
`append` will add the imported character to the end of the character list.
`override` will override the character with the same `name` or `id` as the imported character.
`merge` will replace all non-default values of the character referenced by the `name` or `id` with the values of the imported character.
Defaults to `append`.
`findMode`: Determines how the game will find the character to override/merge. `id` will use the id, `name` will use the name, and `name_then_id` will first try to find the character by name, and if that fails, by id. Defaults to `name_then_id`.
`findName`: Is the name of the character to find if `findMode` is set to `name` or `name_then_id`. If `findMode` is not set, `characterData.name` will be used.
Imported JSON files will be automatically deleted after the game is saved (unless the config option `DeleteImportedCharacters` is set to `false`).

## Uploading mods

Expand Down
61 changes: 49 additions & 12 deletions Saves/BetterCharacterData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public class BetterCharacterData

public BetterCostumeData[] costumeC;

public int[] scar = new int[17];
public int?[] scar = new int?[17];

public float[] stat = new float[7];
public float?[] stat = new float?[7];

public float[] oldStat = new float[7];
public float?[] oldStat = new float?[7];

public float[] newStat = new float[7];
public float?[] newStat = new float?[7];

public float? health;

Expand Down Expand Up @@ -81,25 +81,25 @@ public class BetterCharacterData

public int? oldFed;

public int[] experience = new int[11];
public int?[] experience = new int?[11];

public string[] relationshipC = new string[7];

public int? negotiated;

public int? agreement;

public int[] moveFront = new int[17];
public int?[] moveFront = new int?[17];

public int[] moveBack = new int[9];
public int?[] moveBack = new int?[9];

public int[] moveGround = new int[7];
public int?[] moveGround = new int?[7];

public int[] moveAttack = new int[9];
public int?[] moveAttack = new int?[9];

public int[] moveCrush = new int[9];
public int?[] moveCrush = new int?[9];

public int[] taunt = new int[4];
public int?[] taunt = new int?[4];

public int? stance;

Expand Down Expand Up @@ -211,6 +211,43 @@ public Character ToRegularCharacter(Character[] allCharacters)

public void MergeIntoCharacter(Character character)
{
JsonConvert.PopulateObject(JsonConvert.SerializeObject(this), character);
foreach (var field in typeof(BetterCharacterData).GetFields())
{
if (field.FieldType.IsArray)
{
var array = (Array) field.GetValue(this);
if (array == null)
{
continue;
}
var allNull = true;
var allNonNull = true;
foreach (var element in array)
{
if (element != null)
{
allNull = false;
}
else
{
allNonNull = false;
}
}
if (allNull)
{
field.SetValue(this, null);
}
else if (!allNonNull)
{
throw new Exception("It is not possible to merge arrays with both null and non-null elements.");
}
}
}

// Ignore nulls and nulls in arrays
JsonConvert.PopulateObject(JsonConvert.SerializeObject(this), character, new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
});
}
}
5 changes: 4 additions & 1 deletion Saves/ContentMappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public void AddPreviouslyImportedCharacter(string name, int id)
}

this.PreviouslyImportedCharacters.Add(name);
this.PreviouslyImportedCharacterIds.Add(id);
if (id > 0 && !this.PreviouslyImportedCharacterIds.Contains(id))
{
this.PreviouslyImportedCharacterIds.Add(id);
}
}
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"namespace": "IngoH",
"name": "WECCL",
"description": "Loads custom content for Wrestling Empire",
"version_number": "1.3.2",
"version_number": "1.3.3",
"dependencies": [
"BepInEx-BepInExPack-5.4.2100"
],
Expand Down

0 comments on commit e882a2b

Please sign in to comment.