From 0adc65054ce9e283911141f1563545f1e9ac9e6e Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Thu, 15 Sep 2022 18:19:50 +0300 Subject: [PATCH] Decompile mapLocalVariablesInit --- src/map.cc | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/map.cc b/src/map.cc index 4de706b..29f1391 100644 --- a/src/map.cc +++ b/src/map.cc @@ -53,6 +53,7 @@ static void isoWindowRefreshRectMapper(Rect* rect); static int mapGlobalVariablesInit(int count); static void mapGlobalVariablesFree(); static int mapGlobalVariablesLoad(File* stream); +static int mapLocalVariablesInit(int count); static void mapLocalVariablesFree(); static void _map_place_dude_and_mouse(); static void _square_reset(); @@ -833,18 +834,13 @@ static int mapLoad(File* stream) goto err; } - error = "Error loading local vars"; - mapLocalVariablesFree(); - - if (gMapHeader.localVariablesCount != 0) { - gMapLocalVars = (int*)internal_malloc(sizeof(*gMapLocalVars) * gMapHeader.localVariablesCount); - if (gMapLocalVars == NULL) { - goto err; - } - - gMapLocalVarsLength = gMapHeader.localVariablesCount; + error = "Error allocating local vars"; + // NOTE: Uninline. + if (mapLocalVariablesInit(gMapHeader.localVariablesCount) != 0) { + goto err; } + error = "Error loading local vars"; if (fileReadInt32List(stream, gMapLocalVars, gMapLocalVarsLength) != 0) { goto err; } @@ -1539,6 +1535,25 @@ static int mapGlobalVariablesLoad(File* stream) return 0; } +// NOTE: Inlined. +// +// 0x484080 +static int mapLocalVariablesInit(int count) +{ + mapLocalVariablesFree(); + + if (count != 0) { + gMapLocalVars = (int*)internal_malloc(sizeof(*gMapLocalVars) * count); + if (gMapLocalVars == NULL) { + return -1; + } + } + + gMapLocalVarsLength = count; + + return 0; +} + // 0x4840D4 static void mapLocalVariablesFree() {