-
Notifications
You must be signed in to change notification settings - Fork 64
Remove hardcoded server constants and use parsed constants from Server.m2d / constants.xml #661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mfranca0009
wants to merge
27
commits into
MS2Community:master
Choose a base branch
from
mfranca0009:Issue317
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
3c5c5d5
Add Constants WIP
mfranca0009 55c8d2a
Organize and clean-up old constants values WIP. Start using new serve…
mfranca0009 e11eec4
Continue switching hard coded constants to server constants parsed du…
mfranca0009 af10dca
Continue switching hard coded constants to server constants pared dur…
mfranca0009 3f5414d
Continue switching hard coded constants to server constants pared dur…
mfranca0009 f633b68
Fix last hard coded constant value in PartyManager. Add in input clea…
mfranca0009 24c70fa
Remove hard coded constants and utilize server constants within Inven…
mfranca0009 dff14e7
Update the constant parsing to make it more efficient by removing the…
mfranca0009 5d6f087
Correct some misspelt property names in ConstantsTable record to allo…
mfranca0009 a31f930
Add Xml.m2d constants.xml within the Server.m2d constants.xml parsing…
mfranca0009 d1c3b13
Fix a crash at character entering world due to JSON deserialization c…
mfranca0009 2139067
Merge branch 'master' into Issue317
mfranca0009 80ffb23
Fix changes that were deleted during merge conflict resolution. Added…
mfranca0009 8adfa4d
Took CodeRabbit suggestion since it pointed out unreachable branches …
mfranca0009 91ae45c
Remove accidental default values from hardcoded constants in Constant…
mfranca0009 9cd72f1
Fix a mismatch of currency being used and currency error message bein…
mfranca0009 d54d651
Replace Parse calls with TryParse to prevent runtime crashes. Additio…
mfranca0009 a8e748b
Changes per feedback from Zin
mfranca0009 1b27496
Changes per feedback from Zin #2
mfranca0009 da59e29
Correct NpcLastSight* constant values after adding them back from fee…
mfranca0009 fbb0b5c
Update per Zin's feedback round 3
mfranca0009 0b3b2c6
Revert removal of statLimits from ConfigManager, it is used in two pl…
mfranca0009 3f1a87c
Remove the last unneccessary ConstantsTable parameter and fix some od…
mfranca0009 efcb5ed
Fix mistake on unncessary ConstantsTable parameter removal
mfranca0009 377eed0
Run dotnet format
mfranca0009 c86521a
Fix dotnet format fail
mfranca0009 6eb2b5c
Make adjustments based off coderabbitai suggestions.
mfranca0009 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| using System.Globalization; | ||
| using System.Numerics; | ||
| using System.Reflection; | ||
|
|
||
| namespace Maple2.File.Ingest.Utils; | ||
|
|
||
| public static class GenericHelper { | ||
| public static void SetValue(PropertyInfo prop, object? obj, object? value) { | ||
| if (obj == null && value == null || value == null) return; | ||
| HandleNonIConvertibleTypes(prop, ref value); | ||
| if (value == null) return; | ||
| if (typeof(IConvertible).IsAssignableFrom(prop.PropertyType)) { | ||
| TryParseObject(prop.PropertyType, value, out object? result); | ||
| prop.SetValue(obj, result); | ||
| return; | ||
| } | ||
| prop.SetValue(obj, value); | ||
| } | ||
|
|
||
| private static object? HandleNonIConvertibleTypes(PropertyInfo prop, ref object? value) { | ||
| if (value == null) return value; | ||
| // Handle TimeSpan type | ||
| if (prop.PropertyType == typeof(TimeSpan)) { | ||
| TimeSpan.TryParse((string) value, CultureInfo.InvariantCulture, out TimeSpan val); | ||
| value = val; | ||
| } | ||
| // Handle array types (int[], short[], etc.) | ||
| if (prop.PropertyType.IsArray) { | ||
| var elementType = prop.PropertyType.GetElementType(); | ||
| if (elementType == null) return value; | ||
| string[] segments = ((string) value).Split(','); | ||
| Array destinationArray = Array.CreateInstance(elementType, segments.Length); | ||
| for (int i = 0; i < segments.Length; i++) { | ||
| if (TryParseObject(elementType, segments[i].Trim(), out object? parseResult)) { | ||
| destinationArray.SetValue(parseResult ?? default, i); | ||
| }else { | ||
| destinationArray.SetValue(elementType.IsValueType ? Activator.CreateInstance(elementType) : null, i); | ||
| } | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| value = destinationArray; | ||
| } | ||
| // Handle Vector3 type | ||
| if (prop.PropertyType == typeof(Vector3)) { | ||
| string[] parts = ((string) value).Split(','); | ||
| bool parseXSuccess = float.TryParse(parts[0], CultureInfo.InvariantCulture, out float x); | ||
| bool parseYSuccess = float.TryParse(parts[1], CultureInfo.InvariantCulture, out float y); | ||
| bool parseZSuccess = float.TryParse(parts[2], CultureInfo.InvariantCulture, out float z); | ||
| if (parts.Length != 3 || parseXSuccess && parseYSuccess && parseZSuccess) { | ||
| value = Vector3.Zero; | ||
| } else { | ||
| value = new Vector3(x, y, z); | ||
| } | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return value; | ||
| } | ||
|
|
||
| private static bool TryParseObject(Type? elementType, object? input, out object? result) { | ||
| if (elementType == null || input == null) { | ||
| result = null; | ||
| return false; | ||
| } | ||
|
|
||
| string inputString = Convert.ToString(input, CultureInfo.InvariantCulture)!; | ||
|
|
||
| // No TryParse method exists for a string, use the result directly. | ||
| if (elementType == typeof(string)) { | ||
| result = inputString; | ||
| return true; | ||
| } | ||
|
|
||
| Type[] argTypes = { | ||
| typeof(string), | ||
| typeof(IFormatProvider), | ||
| elementType.MakeByRefType() | ||
| }; | ||
|
|
||
| var method = elementType.GetMethod("TryParse", | ||
| BindingFlags.Public | BindingFlags.Static, | ||
| null, argTypes, null); | ||
| if (method != null) { | ||
| object[] args = [inputString, CultureInfo.InvariantCulture, null!]; | ||
| bool success = (bool) method.Invoke(null, args)!; | ||
| result = args[2]; | ||
| return success; | ||
| } | ||
|
|
||
| // Fallback without CultureInfo provided, in case the type does not have a CultureInfo overload. | ||
| Type[] simpleArgs = { typeof(string), elementType.MakeByRefType() }; | ||
| method = elementType.GetMethod("TryParse", | ||
| BindingFlags.Public | BindingFlags.Static, | ||
| null, simpleArgs, null); | ||
| if (method != null) { | ||
| object[] args = { inputString, null! }; | ||
| bool success = (bool) method.Invoke(null, args)!; | ||
| result = args[1]; | ||
| return success; | ||
| } | ||
|
|
||
|
|
||
| result = null; | ||
| return false; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.