refactor(storm): one wrapper for SMemAlloc and SMemFree

Storm's SMemAlloc (FUN_STORM_SMEM_ALLOC, 0x006462E0) and SMemFree
(FUN_STORM_SMEM_FREE, 0x00646430), both __stdcall with four arguments,
were called by hand in thirteen files, through AddOns::EngineIO's
typedefs, local typedefs, Event::Custom's own pair and
Frame::Subclass::Allocate.

storm/Memory.h now holds Storm::Alloc, with a zero-fill option for the
flag bit 3 (Offsets::STORM_SMEM_FLAG_ZERO_FILL), and Storm::Free. Every
caller uses them, with the same file and line labels as before; the
EngineIO typedefs, Custom's pair and Subclass::Allocate are gone.
This commit is contained in:
Brues
2026-11-09 11:51:27 -06:00
parent b08d2fe813
commit f58cccc86f
17 changed files with 84 additions and 85 deletions
+1
View File
@@ -9753,6 +9753,7 @@ enum Offsets {
// engine's reload teardown loop (which `SMemFree`s every event entry's
// name) doesn't trip its safety check on our injected pointers.
FUN_STORM_SMEM_ALLOC = 0x006462E0,
STORM_SMEM_FLAG_ZERO_FILL = 0x08, // SMemAlloc flags bit 3
FUN_STORM_SMEM_FREE = 0x00646430,
// Engine's main file-content reader. Used by the TOC parser at
+3 -7
View File
@@ -77,6 +77,7 @@
#include "addons/TocRewrite.h"
#include "bindings/Inject.h"
#include "embed/Resource.h"
#include "storm/Memory.h"
#include <cstdint>
#include <cstdio>
@@ -153,8 +154,6 @@ Embed::Bytes LookupEmbedded(const char *relPath) {
// by the caller's standard SMemFree in turn.
using AddOns::EngineIO::FileExistsFn;
using AddOns::EngineIO::FileReadFn;
using AddOns::EngineIO::SMemAllocFn;
using AddOns::EngineIO::SMemFreeFn;
// The trampolines to the original FUN_FILE_READ / FUN_FILE_EXISTS (installed
// by the co-hooks below).
@@ -277,8 +276,7 @@ void DecideSource(int addon) {
// Free the disk buffer we just borrowed — we only needed it for
// the version-line scrape. The actual content for the engine's
// TOC read comes through the regular hook path below.
auto SMemFree = reinterpret_cast<SMemFreeFn>(Offsets::FUN_STORM_SMEM_FREE);
SMemFree(diskBuf, __FILE__, __LINE__, 0);
Storm::Free(diskBuf, __FILE__, __LINE__);
// Missing or unparseable disk version → assume it's older than
// anything we ship, embedded wins.
@@ -320,10 +318,8 @@ int ReadAddonFile(int addon, const char *relPath, int unused, const char *path,
flag1, flag2);
}
auto SMemAlloc = reinterpret_cast<SMemAllocFn>(
Offsets::FUN_STORM_SMEM_ALLOC);
const size_t totalSize = entry.size + extraBytes;
void *buf = SMemAlloc(totalSize, __FILE__, __LINE__, 0);
void *buf = Storm::Alloc(totalSize, __FILE__, __LINE__);
if (buf == nullptr) return 0;
std::memcpy(buf, entry.data, entry.size);
if (extraBytes > 0) {
+1 -5
View File
@@ -32,10 +32,6 @@ using FileReadFn = int(__stdcall *)(int unused, const char *path, void **outBuf,
// FUN_FILE_EXISTS (0x00648A30) — __stdcall, RET 8.
using FileExistsFn = int(__stdcall *)(const char *path, int mode);
// FUN_STORM_SMEM_ALLOC / FUN_STORM_SMEM_FREE — __stdcall, RET 0x10. Buffers
// FUN_FILE_READ hands out are freed with SMemFreeFn; a buffer we allocate with
// SMemAllocFn is freed cleanly by the engine's own SMemFree in turn.
using SMemAllocFn = void *(__stdcall *)(size_t size, const char *file, int line, int flags);
using SMemFreeFn = void(__stdcall *)(void *buf, const char *file, int line, int flags);
// Buffers FUN_FILE_READ hands out are freed with Storm::Free (storm/Memory.h).
} // namespace AddOns::EngineIO
+2 -3
View File
@@ -34,6 +34,7 @@
#include "addons/EngineIO.h"
#include "addons/Toc.h"
#include "luasyntax/AddonNamespace.h"
#include "storm/Memory.h"
#include <cstddef>
#include <cstdint>
@@ -51,7 +52,6 @@ using IsLoadedFn_t = uint8_t(__fastcall *)(const char *name);
// FUN_FILE_READ address routes through Embedded's file-read hook, which forwards
// every non-`!!!ClassicAPI` path to the original untouched — what we want here.
using AddOns::EngineIO::FileReadFn;
using AddOns::EngineIO::SMemFreeFn;
// True iff the addon's `.toc` has a line `## AllowAddOnTableAccess: <nonzero>`.
// The value is read as a TOC boolean flag: parse the leading integer, true iff
@@ -87,8 +87,7 @@ bool TocAllowsTableAccess(const char *name) {
allowed = anyDigit && value != 0;
}
auto smemFree = reinterpret_cast<SMemFreeFn>(Offsets::FUN_STORM_SMEM_FREE);
smemFree(buf, __FILE__, __LINE__, 0);
Storm::Free(buf, __FILE__, __LINE__);
return allowed;
}
+2 -3
View File
@@ -86,6 +86,7 @@
#include "addons/Embedded.h"
#include "addons/EngineIO.h"
#include "addons/Registry.h"
#include "storm/Memory.h"
#include <algorithm>
#include <cstdint>
@@ -235,9 +236,7 @@ bool TryHashToc(const char *name, uint32_t *outHash) {
if (!ReadToc(name, &buf, &size))
return false;
*outHash = HashTocMetadata(static_cast<const char *>(buf), size);
reinterpret_cast<AddOns::EngineIO::SMemFreeFn>(
static_cast<uintptr_t>(Offsets::FUN_STORM_SMEM_FREE))(
buf, __FILE__, __LINE__, 0);
Storm::Free(buf, __FILE__, __LINE__);
return true;
}
+2 -3
View File
@@ -48,6 +48,7 @@
#include "addons/EngineIO.h"
#include "addons/Toc.h"
#include "script/LoadFile.h"
#include "storm/Memory.h"
#include <cstddef>
#include <cstdint>
@@ -66,7 +67,6 @@ constexpr size_t NPOS = static_cast<size_t>(-1);
// FlavorToc applies), the exists-check, and the Storm free. See addons/EngineIO.h.
using AddOns::EngineIO::FileExistsFn;
using AddOns::EngineIO::FileReadFn;
using AddOns::EngineIO::SMemFreeFn;
using LoadTocFilesFn = uint32_t(__fastcall *)(char *tocPath, int *a2, int *a3);
using NameFn = const char *(*)(); // no-arg readers (return in EAX)
@@ -160,8 +160,7 @@ SvFlags ReadSvFlags(const char *tocPath) {
f.perChar =
AddOns::Toc::FindValue(b, size, "SavedVariablesPerCharacter", &v, &n) && n > 0;
reinterpret_cast<SMemFreeFn>(static_cast<uintptr_t>(Offsets::FUN_STORM_SMEM_FREE))(
buf, __FILE__, __LINE__, 0);
Storm::Free(buf, __FILE__, __LINE__);
return f;
}
+3 -6
View File
@@ -17,6 +17,7 @@
#include "localization/Locale.h"
#include "Offsets.h"
#include "storm/Memory.h"
#include "turtle/Detect.h"
#include <cstddef>
@@ -28,8 +29,6 @@ namespace AddOns::TocRewrite {
namespace {
using AddOns::EngineIO::SMemAllocFn;
using AddOns::EngineIO::SMemFreeFn;
using AddOns::Toc::EqCI;
using AddOns::Toc::Lower;
@@ -288,15 +287,13 @@ void Transform(const char *path, void **outBuf, size_t *outSize) {
std::memcmp(rebuilt.data(), content, size) == 0)
return; // brackets/commas were only in unaffected lines — nothing changed
auto SMemAlloc = reinterpret_cast<SMemAllocFn>(Offsets::FUN_STORM_SMEM_ALLOC);
auto SMemFree = reinterpret_cast<SMemFreeFn>(Offsets::FUN_STORM_SMEM_FREE);
const size_t newLen = rebuilt.size();
void *buf = SMemAlloc(newLen + 1, __FILE__, __LINE__, 0); // +1 NUL (extraBytes=1)
void *buf = Storm::Alloc(newLen + 1, __FILE__, __LINE__); // +1 NUL (extraBytes=1)
if (buf == nullptr) return; // OOM — keep the original
std::memcpy(buf, rebuilt.data(), newLen);
static_cast<char *>(buf)[newLen] = '\0';
SMemFree(*outBuf, __FILE__, __LINE__, 0);
Storm::Free(*outBuf, __FILE__, __LINE__);
*outBuf = buf;
if (outSize != nullptr) *outSize = newLen;
}
+3 -6
View File
@@ -49,6 +49,7 @@
#include "Inject.h"
#include "Common.h"
#include "Offsets.h"
#include "storm/Memory.h"
#include "embed/Resource.h"
#include "embedded_resources.h"
@@ -213,8 +214,6 @@ const char *FindSplicePosition(const char *content, size_t size,
return FindOutsideComment(content, end, "</Bindings>");
}
using SMemAlloc_t = void *(__stdcall *)(size_t size, const char *file, int line, int flags);
using SMemFree_t = void(__stdcall *)(void *buf, const char *file, int line, int flags);
} // namespace
@@ -257,10 +256,8 @@ bool TryHandle(int unused, const char *path, void **outBuf, size_t *outSize,
const size_t splicePos = static_cast<size_t>(splice - content);
const size_t newSize = origSize + config.innerSize;
auto SMemAlloc = reinterpret_cast<SMemAlloc_t>(Offsets::FUN_STORM_SMEM_ALLOC);
auto SMemFree = reinterpret_cast<SMemFree_t>(Offsets::FUN_STORM_SMEM_FREE);
void *newBuf = SMemAlloc(newSize + extraBytes, __FILE__, __LINE__, 0);
void *newBuf = Storm::Alloc(newSize + extraBytes, __FILE__, __LINE__);
if (newBuf == nullptr) {
// Allocation failed — fall back to the original buffer so the
// engine still loads its own bindings.
@@ -277,7 +274,7 @@ bool TryHandle(int unused, const char *path, void **outBuf, size_t *outSize,
if (extraBytes > 0)
std::memset(dest + newSize, 0, extraBytes);
SMemFree(origBuf, __FILE__, __LINE__, 0);
Storm::Free(origBuf, __FILE__, __LINE__);
if (outBuf != nullptr) *outBuf = newBuf;
if (outSize != nullptr) *outSize = newSize;
+2 -2
View File
@@ -46,6 +46,7 @@
#include "baselib/Ascii.h"
#include "frame/ClickEvents.h"
#include "input/Modifier.h"
#include "storm/Memory.h"
#include "xml/FrameLoad.h"
#include <cstdint>
@@ -219,8 +220,7 @@ void LoadModifiedClicks(const char *path, void *status) {
return;
void *tree = reinterpret_cast<TreeLoad_t>(Offsets::FUN_XML_TREE_LOAD)(
static_cast<const char *>(data), static_cast<uint32_t>(size));
reinterpret_cast<AddOns::EngineIO::SMemFreeFn>(Offsets::FUN_STORM_SMEM_FREE)(data, __FILE__,
__LINE__, 0);
Storm::Free(data, __FILE__, __LINE__);
if (tree == nullptr)
return; // the engine loader reports the parse error
const void *root = Game::Read<const void *>(tree, 0);
+7 -19
View File
@@ -19,6 +19,7 @@
#include "frame/ScriptArgs.h"
#include "frame/UnitEvent.h"
#include "profile/ScriptTime.h"
#include "storm/Memory.h"
#include <cstdint>
#include <cstring>
@@ -94,23 +95,6 @@ char *SStrDup(const char *s) {
return fn(s, __FILE__, __LINE__);
}
// Storm allocator/free — the same pair the engine uses for the event-table
// buffer (see RebuildEventTable), so its reload teardown `SMemFree`s our
// grown buffer exactly as its own. Both `__stdcall`, 4 args (`ret 0x10`).
// SMemAlloc flag bit 8 zero-fills (matching SetEventCount's fresh entries).
void *SMemAlloc(unsigned size) {
using SMemAlloc_t = void *(__stdcall *)(unsigned size, const char *file,
int line, int flags);
auto fn = reinterpret_cast<SMemAlloc_t>(Offsets::FUN_STORM_SMEM_ALLOC);
return fn(size, __FILE__, __LINE__, 8 /* zero-fill */);
}
void SMemFree(void *ptr) {
using SMemFree_t = int(__stdcall *)(void *ptr, const char *file, int line,
int flags);
auto fn = reinterpret_cast<SMemFree_t>(Offsets::FUN_STORM_SMEM_FREE);
fn(ptr, __FILE__, __LINE__, 0);
}
// True when slot `id` of the live table can take one of our names: its name
// is NULL (no one owns it) AND the engine never signals it by number. A NULL
// name alone is not enough — the glue band (ids below GLUE_EVENT_COUNT) and
@@ -294,8 +278,12 @@ void Grow() {
constexpr int kMargin = 16;
const int deficit = (nulls < demand) ? (demand - nulls) : 0;
const int newCount = count + deficit + kMargin;
// Storm's heap, like the engine's own table buffer (see RebuildEventTable),
// so its reload teardown SMemFrees ours the same way; zero-filled, like
// SetEventCount's fresh entries.
auto *newBuf = static_cast<uint8_t *>(
SMemAlloc(static_cast<unsigned>(newCount) * Offsets::EVENT_ENTRY_STRIDE));
Storm::Alloc(static_cast<size_t>(newCount) * Offsets::EVENT_ENTRY_STRIDE, __FILE__,
__LINE__, true));
if (newBuf == nullptr)
return; // alloc failed — keep the old table; claiming still works
@@ -323,7 +311,7 @@ void Grow() {
Game::Ref<uint8_t *>(Offsets::VAR_EVENT_TABLE_BASE_PTR) = newBuf;
Game::Ref<int>(Offsets::VAR_EVENT_TABLE_CAP) = newCount;
Game::Ref<int>(Offsets::VAR_EVENT_TABLE_COUNT) = newCount;
SMemFree(base);
Storm::Free(base, __FILE__, __LINE__);
Debug::Log::Printf("[event] grew table %d -> %d (%d NULL, %d reserved%s)",
count, newCount, nulls, demand,
-7
View File
@@ -21,7 +21,6 @@ namespace {
// static initialization whatever the order of the translation units.
MethodHash *g_hashes = nullptr;
using SMemAlloc_t = void *(__stdcall *)(size_t size, const char *file, int line, int flags);
using RegisterFactory_t = int(__fastcall *)(const char *type, Factory_t factory, int unique);
using PushMethod_t = int(__fastcall *)(void *L, const char *name, void *hash);
using UnregisterMethods_t = void(__fastcall *)(void *hash);
@@ -41,12 +40,6 @@ const Game::HookAutoRegister _unregisterHook{
} // namespace
void *Allocate(size_t size, const char *file, int line) {
constexpr int kZeroFill = 0x08;
return reinterpret_cast<SMemAlloc_t>(Offsets::FUN_STORM_SMEM_ALLOC)(size, file, line,
kZeroFill);
}
void RegisterFactory(const char *type, Factory_t factory) {
reinterpret_cast<RegisterFactory_t>(Offsets::FUN_FRAMEXML_REGISTER_FACTORY)(type, factory, 0);
}
+6 -8
View File
@@ -21,6 +21,7 @@
#include "Game.h"
#include "Offsets.h"
#include "frame/Layout.h"
#include "storm/Memory.h"
#include <cstddef>
#include <cstdint>
@@ -180,17 +181,14 @@ bool BuildVTables() {
return true;
}
// The allocation an engine factory makes (the "Frame" one, 0x006EEC10), sized
// for the whole object and zero-filled; null when it fails.
void *Allocate(size_t size, const char *file, int line);
// A new frame of the class, shaped like the engine's factories: the block
// (our part zero), the engine class's constructor, then our vtables, which
// BuildVTables must have built. Null when the allocation fails.
// A new frame of the class, shaped like the engine's factories (the "Frame"
// one, 0x006EEC10): a Storm block for the whole object, zero-filled, the
// engine class's constructor, then our vtables, which BuildVTables must have
// built. Null when the allocation fails.
template <auto &C>
void *New(void *parent) {
using Constructor_t = void(__fastcall *)(void *self, void *edx, void *parent);
void *frame = Allocate(C.size, __FILE__, __LINE__);
void *frame = Storm::Alloc(C.size, __FILE__, __LINE__, true);
if (frame == nullptr)
return nullptr;
reinterpret_cast<Constructor_t>(C.constructor)(frame, nullptr, parent);
+2 -3
View File
@@ -93,6 +93,7 @@
#include "Game.h"
#include "Offsets.h"
#include "debug/Log.h"
#include "storm/Memory.h"
#include <windows.h>
@@ -114,7 +115,6 @@ namespace {
using FileRead_t = int(__stdcall *)(int unused, const char *path, void **outBuf,
unsigned int *outSize, unsigned int extraBytes,
int flag1, int flag2);
using SMemFree_t = void(__stdcall *)(void *ptr, const char *file, int line, int flags);
// MPQ enumerator (see Offsets::FUN_MPQ_ENUM_FILES). The callback
// receives each listfile entry's full path in ecx; returning 0 STOPS
@@ -301,7 +301,6 @@ void ScanPathGetters(Collector &c) {
int WriteFiles(const std::vector<std::string> &files, size_t prefixLen,
const char *dstRoot, int *skipped) {
auto FileRead = reinterpret_cast<FileRead_t>(Offsets::FUN_FILE_READ);
auto SMemFree = reinterpret_cast<SMemFree_t>(Offsets::FUN_STORM_SMEM_FREE);
int written = 0;
int missed = 0;
@@ -327,7 +326,7 @@ int WriteFiles(const std::vector<std::string> &files, size_t prefixLen,
static_cast<unsigned long>(GetLastError()), dst.c_str());
}
SMemFree(buf, __FILE__, __LINE__, 0);
Storm::Free(buf, __FILE__, __LINE__);
}
if (skipped != nullptr)
*skipped = missed;
+4 -6
View File
@@ -56,6 +56,7 @@
#include "Game.h"
#include "Offsets.h"
#include "scrollingmessageframe/DisplayRefreshed.h"
#include "storm/Memory.h"
#include <algorithm>
#include <cstdint>
@@ -265,8 +266,6 @@ uint32_t MessageColor(void *L, void *frame) {
// out as before (a hidden frame's layout places nothing).
int __fastcall Script_BackFillMessage(void *L) {
using namespace Game::Lua;
using StormAlloc_t = void *(__stdcall *)(size_t size, const char *file, int line, int flags);
using StormFree_t = int(__stdcall *)(void *ptr, const char *file, int line, int flags);
using Layout_t = void(__fastcall *)(void *smf, void *edx, int newestRecord);
static const char kStormFile[] = "ClassicAPI ScrollingMessageFrame:BackFillMessage";
@@ -284,7 +283,7 @@ int __fastcall Script_BackFillMessage(void *L) {
const uint32_t color = MessageColor(L, frame);
const size_t bytes = std::strlen(text) + 1;
char *copy = static_cast<char *>(
reinterpret_cast<StormAlloc_t>(Offsets::FUN_STORM_SMEM_ALLOC)(bytes, kStormFile, __LINE__, 0));
Storm::Alloc(bytes, kStormFile, __LINE__));
if (copy == nullptr)
return 0;
std::memcpy(copy, text, bytes);
@@ -298,7 +297,7 @@ int __fastcall Script_BackFillMessage(void *L) {
uint8_t *record = Game::Read<uint8_t *>(frame, Offsets::OFF_SCROLLINGMESSAGEFRAME_MESSAGES);
char *&stored = *reinterpret_cast<char **>(record + Offsets::OFF_SCROLLINGMESSAGEFRAME_MESSAGE_TEXT);
if (stored != nullptr)
reinterpret_cast<StormFree_t>(Offsets::FUN_STORM_SMEM_FREE)(stored, kStormFile, __LINE__, 0);
Storm::Free(stored, kStormFile, __LINE__);
stored = copy;
*reinterpret_cast<uint32_t *>(record + Offsets::OFF_SCROLLINGMESSAGEFRAME_MESSAGE_COLOR) = color;
*reinterpret_cast<int *>(record + Offsets::OFF_SCROLLINGMESSAGEFRAME_MESSAGE_SHOWN) = 1;
@@ -399,7 +398,6 @@ int __fastcall Script_RemoveMessagesByPredicate(void *L) {
using Layout_t = void(__fastcall *)(void *smf, void *edx, int newestRecord);
using Smf_t = void(__fastcall *)(void *smf);
using ScrollOffset_t = int(__fastcall *)(void *smf);
using StormFree_t = int(__stdcall *)(void *ptr, const char *file, int line, int flags);
static const char kStormFile[] = "ClassicAPI ScrollingMessageFrame:RemoveMessagesByPredicate";
void *frame = ResolveTypedObject(L, 1, Offsets::VAR_SCROLLINGMESSAGEFRAME_LUA_TYPE_ID);
@@ -460,7 +458,7 @@ int __fastcall Script_RemoveMessagesByPredicate(void *L) {
uint8_t *from = records + src * Offsets::SCROLLINGMESSAGEFRAME_MESSAGE_STRIDE;
char *&landedOn = *reinterpret_cast<char **>(to + Offsets::OFF_SCROLLINGMESSAGEFRAME_MESSAGE_TEXT);
if (landedOn != nullptr)
reinterpret_cast<StormFree_t>(Offsets::FUN_STORM_SMEM_FREE)(landedOn, kStormFile, __LINE__, 0);
Storm::Free(landedOn, kStormFile, __LINE__);
std::memcpy(to, from, Offsets::SCROLLINGMESSAGEFRAME_MESSAGE_STRIDE);
*reinterpret_cast<char **>(from + Offsets::OFF_SCROLLINGMESSAGEFRAME_MESSAGE_TEXT) = nullptr;
if (extras) {
+41
View File
@@ -0,0 +1,41 @@
// This file is part of ClassicAPI.
//
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
// of the GNU General Public License as published by the Free Software Foundation, either
// version 3 of the License, or (at your option) any later version.
//
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
#pragma once
// Storm's heap (Offsets.h, at FUN_STORM_SMEM_ALLOC): the blocks the engine
// allocates and frees itself. A block the engine will free must come from
// Alloc, and a block the engine hands over is freed with Free; SMemFree
// rejects any other pointer (ERROR #124). `file` and `line` label the block
// in Storm's bookkeeping.
#include "Offsets.h"
#include <cstddef>
namespace Storm {
// SMemAlloc: null when out of memory.
inline void *Alloc(size_t size, const char *file, int line, bool zeroFill = false) {
using Fn = void *(__stdcall *)(size_t, const char *, int, int);
return reinterpret_cast<Fn>(Offsets::FUN_STORM_SMEM_ALLOC)(
size, file, line, zeroFill ? Offsets::STORM_SMEM_FLAG_ZERO_FILL : 0);
}
// SMemFree.
inline void Free(void *ptr, const char *file, int line) {
using Fn = int(__stdcall *)(void *, const char *, int, int);
reinterpret_cast<Fn>(Offsets::FUN_STORM_SMEM_FREE)(ptr, file, line, 0);
}
} // namespace Storm
+3 -5
View File
@@ -116,6 +116,7 @@
#include "Common.h"
#include "Game.h"
#include "Offsets.h"
#include "storm/Memory.h"
#include <windows.h>
@@ -197,7 +198,6 @@ constexpr const char *kAllocTag = "ClassicAPI/texture/DimensionGate.cpp";
using DecodeBufferAlloc_t = void *(__fastcall *)(int format, uint32_t width, uint32_t height,
const char *file, uint32_t line);
using SMemFree_t = void(__stdcall *)(void *buf, const char *file, int line, int flags);
void *g_retiredScratch = nullptr; // the previous scratch, freed at the next growth
@@ -224,8 +224,7 @@ bool GrowScratch(uint32_t side) {
// means any holder not accounted for reads stale bytes instead of unmapped
// memory. Bounded: one buffer, freed at the next growth.
if (g_retiredScratch != nullptr)
reinterpret_cast<SMemFree_t>(Offsets::FUN_STORM_SMEM_FREE)(g_retiredScratch, kAllocTag,
__LINE__, 0);
Storm::Free(g_retiredScratch, kAllocTag, __LINE__);
g_retiredScratch = old;
WriteImm32(Offsets::PATCH_TEXDECODE_SCRATCH_DIM_W + 1, side);
WriteImm32(Offsets::PATCH_TEXDECODE_SCRATCH_DIM_H + 1, side);
@@ -473,8 +472,7 @@ void *__fastcall AllocMips_h(uint32_t format, uint32_t width, uint32_t height) {
void __fastcall FreeMips_h(void *buffer, uint32_t format, uint32_t width, uint32_t height) {
if (!IsPowerOfTwo(width) || !IsPowerOfTwo(height)) {
if (buffer != nullptr)
reinterpret_cast<SMemFree_t>(Offsets::FUN_STORM_SMEM_FREE)(buffer, kAllocTag, __LINE__,
0);
Storm::Free(buffer, kAllocTag, __LINE__);
return;
}
FreeMips_o(buffer, format, width, height);
+2 -2
View File
@@ -46,6 +46,7 @@
#include "Game.h"
#include "Offsets.h"
#include "frame/ScriptBindings.h"
#include "storm/Memory.h"
#include "xml/FrameLoad.h"
#include "xml/Inherits.h"
@@ -60,7 +61,6 @@ using Factory_t = void *(__fastcall *)(void *parent);
using RegisterFactory_t = int(__fastcall *)(const char *type, Factory_t factory, int unique);
using Hash_t = uint32_t(__stdcall *)(const char *s);
using NodeOp_t = void(__fastcall *)(void *node);
using SMemFree_t = void(__stdcall *)(void *ptr, const char *file, int line, int flags);
struct Def {
const char *name; // the node's own `name` attribute
@@ -137,7 +137,7 @@ void Walk(const void *node, void *status, int depth, const Def **found) {
void PrepareForReload() {
for (const Def &d : g_defs) {
reinterpret_cast<NodeOp_t>(Offsets::FUN_XML_NODE_DTOR)(d.node);
reinterpret_cast<SMemFree_t>(Offsets::FUN_STORM_SMEM_FREE)(d.node, __FILE__, __LINE__, 0);
Storm::Free(d.node, __FILE__, __LINE__);
}
g_defs.clear();
}