This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Install the version-checked Classic adapter into an isolated CMaNGOS checkout."""
|
||||
import argparse
|
||||
import pathlib
|
||||
import shutil
|
||||
|
||||
def patch(path, anchor, replacement):
|
||||
text = path.read_text()
|
||||
if replacement in text:
|
||||
return
|
||||
if text.count(anchor) != 1:
|
||||
raise RuntimeError(f"Upstream source changed: {path.name}")
|
||||
path.write_text(text.replace(anchor, replacement))
|
||||
|
||||
def install(source):
|
||||
here = pathlib.Path(__file__).resolve().parent
|
||||
for path in (here / "native").glob("AzerothAI.*"):
|
||||
shutil.copy2(path, source / "src/game/World" / path.name)
|
||||
for relative, anchor, invocation in [
|
||||
("src/game/World/World.cpp", " sMapMgr.Update(diff);", "AzerothAIUpdate(diff);"),
|
||||
("src/game/Entities/Unit.cpp", " uint32 health = victim->GetHealth();", "damage = AzerothAIBoundDamage(victim, damage);")
|
||||
]:
|
||||
path = source / relative
|
||||
include = '#ifdef ENABLE_PLAYERBOTS\n#include "World/AzerothAI.h"\n#endif\n'
|
||||
if include not in path.read_text():
|
||||
path.write_text(include + path.read_text())
|
||||
patch(path, anchor, anchor + "\n#ifdef ENABLE_PLAYERBOTS\n " + invocation + "\n#endif")
|
||||
# Upstream treats unknown gear modes as generated equipment. Explicitly
|
||||
# preserve ordinary character-creation equipment for our level-one roster.
|
||||
path = source / "src/modules/PlayerBots/playerbot/PlayerbotMgr.cpp"
|
||||
anchor = ' sRandomPlayerbotMgr.SetValue(botGuid, "create gear", 1, gear);'
|
||||
patch(path, anchor, ' if (gear != "none")\n ' + anchor)
|
||||
path = source / "src/game/Entities/CharacterHandler.cpp"
|
||||
include = '#ifdef ENABLE_PLAYERBOTS\n#include "World/AzerothAI.h"\n#endif\n'
|
||||
if include not in path.read_text():
|
||||
path.write_text(include + path.read_text())
|
||||
anchor = 'void PlayerbotHolder::AddPlayerBot(uint32 playerGuid, uint32 masterAccount)\n{'
|
||||
patch(path, anchor, anchor + '\n if (!AzerothAIAllowBotLogin(playerGuid)) return;')
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("source", type=pathlib.Path)
|
||||
install(parser.parse_args().source.resolve())
|
||||
Reference in New Issue
Block a user