mirror of
https://gitlab.com/Mr_Goldberg/goldberg_emulator.git
synced 2025-12-05 03:34:52 +01:00
Support achievements that are triggered automatically with stats.
The achievements config MUST be generated with the achievements_gen.py script.
This commit is contained in:
parent
3f8ce69b6d
commit
8695ea2dce
5 changed files with 151 additions and 76 deletions
|
|
@ -4,14 +4,6 @@ import os
|
|||
import json
|
||||
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print("format: {} UserGameStatsSchema_480.bin".format(sys.argv[0]))
|
||||
exit(0)
|
||||
|
||||
|
||||
with open(sys.argv[1], 'rb') as f:
|
||||
schema = vdf.binary_loads(f.read())
|
||||
|
||||
language = 'english'
|
||||
|
||||
STAT_TYPE_INT = '1'
|
||||
|
|
@ -19,68 +11,84 @@ STAT_TYPE_FLOAT = '2'
|
|||
STAT_TYPE_AVGRATE = '3'
|
||||
STAT_TYPE_BITS = '4'
|
||||
|
||||
achievements_out = []
|
||||
stats_out = []
|
||||
def generate_stats_achievements(schema, config_directory):
|
||||
schema = vdf.binary_loads(schema)
|
||||
achievements_out = []
|
||||
stats_out = []
|
||||
|
||||
for appid in schema:
|
||||
sch = schema[appid]
|
||||
stat_info = sch['stats']
|
||||
for s in stat_info:
|
||||
stat = stat_info[s]
|
||||
if stat['type'] == STAT_TYPE_BITS:
|
||||
achs = stat['bits']
|
||||
for ach_num in achs:
|
||||
for appid in schema:
|
||||
sch = schema[appid]
|
||||
stat_info = sch['stats']
|
||||
for s in stat_info:
|
||||
stat = stat_info[s]
|
||||
if stat['type'] == STAT_TYPE_BITS:
|
||||
achs = stat['bits']
|
||||
for ach_num in achs:
|
||||
out = {}
|
||||
ach = achs[ach_num]
|
||||
out["hidden"] = '0'
|
||||
for x in ach['display']:
|
||||
value = ach['display'][x]
|
||||
if x == 'name':
|
||||
x = 'displayName'
|
||||
if x == 'desc':
|
||||
x = 'description'
|
||||
if x == 'Hidden':
|
||||
x = 'hidden'
|
||||
if type(value) is dict:
|
||||
if language in value:
|
||||
value = value[language]
|
||||
else:
|
||||
value = ''
|
||||
out[x] = value
|
||||
out['name'] = ach['name']
|
||||
if 'progress' in ach:
|
||||
out['progress'] = ach['progress']
|
||||
achievements_out += [out]
|
||||
else:
|
||||
out = {}
|
||||
ach = achs[ach_num]
|
||||
out["hidden"] = '0'
|
||||
for x in ach['display']:
|
||||
value = ach['display'][x]
|
||||
if x == 'name':
|
||||
x = 'displayName'
|
||||
if x == 'desc':
|
||||
x = 'description'
|
||||
if x == 'Hidden':
|
||||
x = 'hidden'
|
||||
if type(value) is dict:
|
||||
if language in value:
|
||||
value = value[language]
|
||||
else:
|
||||
value = ''
|
||||
out[x] = value
|
||||
out['name'] = ach['name']
|
||||
achievements_out += [out]
|
||||
else:
|
||||
out = {}
|
||||
out['default'] = 0
|
||||
out['name'] = stat['name']
|
||||
if stat['type'] == STAT_TYPE_INT:
|
||||
out['type'] = 'int'
|
||||
elif stat['type'] == STAT_TYPE_FLOAT:
|
||||
out['type'] = 'float'
|
||||
elif stat['type'] == STAT_TYPE_AVGRATE:
|
||||
out['type'] = 'avgrate'
|
||||
if 'Default' in stat:
|
||||
out['default'] = stat['Default']
|
||||
out['default'] = 0
|
||||
out['name'] = stat['name']
|
||||
if stat['type'] == STAT_TYPE_INT:
|
||||
out['type'] = 'int'
|
||||
elif stat['type'] == STAT_TYPE_FLOAT:
|
||||
out['type'] = 'float'
|
||||
elif stat['type'] == STAT_TYPE_AVGRATE:
|
||||
out['type'] = 'avgrate'
|
||||
if 'Default' in stat:
|
||||
out['default'] = stat['Default']
|
||||
|
||||
stats_out += [out]
|
||||
# print(stat_info[s])
|
||||
stats_out += [out]
|
||||
# print(stat_info[s])
|
||||
|
||||
|
||||
|
||||
output_ach = json.dumps(achievements_out, indent=4)
|
||||
output_stats = ""
|
||||
for s in stats_out:
|
||||
output_stats += "{}={}={}\n".format(s['name'], s['type'], s['default'])
|
||||
output_ach = json.dumps(achievements_out, indent=4)
|
||||
output_stats = ""
|
||||
for s in stats_out:
|
||||
output_stats += "{}={}={}\n".format(s['name'], s['type'], s['default'])
|
||||
|
||||
# print(output_ach)
|
||||
# print(output_stats)
|
||||
# print(output_ach)
|
||||
# print(output_stats)
|
||||
|
||||
config_directory = os.path.join(sys.argv[1] + "_output", "steam_settings")
|
||||
if not os.path.exists(config_directory):
|
||||
os.makedirs(config_directory)
|
||||
if not os.path.exists(config_directory):
|
||||
os.makedirs(config_directory)
|
||||
|
||||
with open(os.path.join(config_directory, "achievements.json"), 'w') as f:
|
||||
f.write(output_ach)
|
||||
with open(os.path.join(config_directory, "achievements.json"), 'w') as f:
|
||||
f.write(output_ach)
|
||||
|
||||
with open(os.path.join(config_directory, "stats.txt"), 'w') as f:
|
||||
f.write(output_stats)
|
||||
with open(os.path.join(config_directory, "stats.txt"), 'w') as f:
|
||||
f.write(output_stats)
|
||||
|
||||
return (output_ach, output_stats)
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 2:
|
||||
print("format: {} UserGameStatsSchema_480.bin".format(sys.argv[0]))
|
||||
exit(0)
|
||||
|
||||
|
||||
with open(sys.argv[1], 'rb') as f:
|
||||
schema = f.read()
|
||||
|
||||
generate_stats_achievements(schema, os.path.join("{}".format( "{}_output".format(sys.argv[1])), "steam_settings"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue